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

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

a = A("a")
j = B("j")
b = B("b")
l = B("l")
h = B("h")
i = A("i")
k = B("k")
d = A("d")
g = A("g")
c = A("c")

a.x = d
j.t = a
b.t = d
l.t = d
h.t = d
i.x = d
k.t = a
d.x = a
g.x = d
c.x = a
assert g.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

a = A("a")
j = B("j")
b = B("b")
l = B("l")
h = B("h")
i = A("i")
k = B("k")
d = A("d")
g = A("g")
c = A("c")

a.x = d
j.t = a
b.t = d
l.t = d
h.t = d
i.x = d
k.t = a
d.x = a
g.x = d
c.x = a
assert g.x.x.x.x.x.x.txt == "a"