← Home
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func gcd(a, b uint64) uint64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var x, y uint64
	if _, err := fmt.Fscan(in, &x, &y); err != nil {
		return
	}

	if x == 0 || y == 0 || gcd(x, y) != 1 {
		fmt.Fprintln(out, "Impossible")
		return
	}

	for x > 1 && y > 1 {
		if x > y {
			q := x / y
			x -= q * y
			out.WriteString(strconv.FormatUint(q, 10))
			out.WriteByte('A')
		} else {
			q := y / x
			y -= q * x
			out.WriteString(strconv.FormatUint(q, 10))
			out.WriteByte('B')
		}
	}

	if x == 1 && y > 1 {
		out.WriteString(strconv.FormatUint(y-1, 10))
		out.WriteByte('B')
	} else if y == 1 && x > 1 {
		out.WriteString(strconv.FormatUint(x-1, 10))
		out.WriteByte('A')
	}
}