```java
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
hanoi(n, 'a', 'b', 'c');
}
private static void hanoi(int n, char a, char b, char c) {
Stack s1 = new Stack<>();
Stack s2 = new Stack<>();
Stack s3 = new Stack<>();
for (int i = n; i > 0; i--) {
s1.push(i);
s2.push(a);
s3.push(c);
}
while (!s1.isEmpty()) {
int num = s1.pop();
char from = s2.pop();
char to = s3.pop();
if (num == 1) {
System.out.println(from + " -> " + to);
} else {
s1.push(num - 1);
s2.push(to);
s3.push(from);
s1.push(1);
s2.push(from);
s3.push(to);
s1.push(num - 1);
s2.push(from);
s3.push(to);
}
}
}
}
```