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

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

a = A("a")
j = B("j")
b = B("b")
e = A("e")
h = B("h")
l = B("l")
g = B("g")
i = A("i")

a.t = e
j.r = h
j.x = g
b.r = g
b.x = l
e.t = a
h.r = b
h.x = b
l.r = g
l.x = b
g.r = l
g.x = l
i.t = e
assert e.t.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.r: B = None
        self.x: B = None
        self.txt = txt

a = A("a")
j = B("j")
b = B("b")
e = A("e")
h = B("h")
l = B("l")
g = B("g")
i = A("i")

a.t = e
j.r = h
j.x = g
b.r = g
b.x = l
e.t = a
h.r = b
h.x = b
l.r = g
l.x = b
g.r = l
g.x = l
i.t = e
assert e.t.t.t.t.t.t.t.txt == "a"