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

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

g = A("g")
a = B("a")
f = B("f")
b = B("b")
d = B("d")
l = B("l")
e = A("e")
h = A("h")

g.x = h
a.t = b
f.t = b
b.t = d
d.t = f
l.t = d
e.x = g
h.x = g
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: B = None
        self.txt = txt

g = A("g")
a = B("a")
f = B("f")
b = B("b")
d = B("d")
l = B("l")
e = A("e")
h = A("h")

g.x = h
a.t = b
f.t = b
b.t = d
d.t = f
l.t = d
e.x = g
h.x = g
assert g.x.x.x.x.x.x.txt == "g"