input: 
  def hanoi(n, source, spare, target):
      """Solve the Towers of Hanoi problem by moving n disks from the source peg to the target peg using the spare peg as an auxiliary.
      >>> input_state = [(i, "A") for i in range(1, 9)]
      >>> target_state = []
      >>> spare_state = []
      >>> hanoi(8, input_state, spare_state, target_state)
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 4 from A to C
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 5 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 4 from C to B
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 6 from A to C
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 4 from B to A
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 5 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 4 from A to C
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 7 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 4 from C to B
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 5 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 4 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 6 from C to B
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 4 from A to C
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 5 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 4 from C to B
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 8 from A to C
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 4 from B to A
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 5 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 4 from A to C
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 6 from B to A
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from B to C
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 4 from C to B
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 5 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 4 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 9 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 4 from C to B
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 5 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 4 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 6 from C to B
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 4 from A to C
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 5 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 4 from C to B
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 3 from A to B
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 7 from A to C
      Moving disk 1 from B to C
      Moving disk 2 from B to A
      Moving disk 1 from C to A
      Moving disk 3 from B to C
      Moving disk 1 from A to B
      Moving disk 2 from A to C
      Moving disk 1 from B to C
      Moving disk 4 from B to A
      Moving disk 1 from C to A
      Moving disk 2 from C to B
      Moving disk 1 from A to B
      Moving disk 3 from C to A
      Moving disk 1 from B to C
      Moving disk
output:     
      if n == 1:
          disk, src_peg = source.pop(0)
          target.append((disk, src_peg))
          print(f"Moving disk {disk} from {src_peg} to {target[-1][1]}")
      else:
          hanoi(n-1, source, target, spare)
          disk, src_peg = source.pop(0)
          target.append((disk, src_peg))
          print(f"Moving disk {disk} from {src_peg} to {target[-1][1]}")
          hanoi(n-1, spare, source, target)
  