class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

h = A("h")
a = B("a")
b = A("b")
j = B("j")
g = B("g")
f = B("f")
n = B("n")
m = A("m")

h.t = m
a.t = b
b.t = h
j.t = b
g.t = m
f.t = h
n.t = h
m.t = b
assert j.t.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

h = A("h")
a = B("a")
b = A("b")
j = B("j")
g = B("g")
f = B("f")
n = B("n")
m = A("m")

h.t = m
a.t = b
b.t = h
j.t = b
g.t = m
f.t = h
n.t = h
m.t = b
assert j.t.t.t.t.t.t.txt == "m"