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

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

h = A("h")
b = B("b")
c = B("c")
e = B("e")
a = B("a")
m = A("m")
d = B("d")
j = A("j")
g = A("g")

h.t = j
b.z = g
b.r = a
c.z = h
c.r = e
e.z = g
e.r = b
a.z = j
a.r = c
m.t = j
d.z = h
d.r = e
j.t = h
g.t = m
assert d.r.r.r.z.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.z: A = None
        self.r: B = None
        self.txt = txt

h = A("h")
b = B("b")
c = B("c")
e = B("e")
a = B("a")
m = A("m")
d = B("d")
j = A("j")
g = A("g")

h.t = j
b.z = g
b.r = a
c.z = h
c.r = e
e.z = g
e.r = b
a.z = j
a.r = c
m.t = j
d.z = h
d.r = e
j.t = h
g.t = m
assert d.r.r.r.z.t.t.t.t.txt == "j"