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

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

g = A("g")
i = B("i")
d = B("d")
l = A("l")
j = A("j")
h = B("h")
n = B("n")
b = B("b")

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

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

g = A("g")
i = B("i")
d = B("d")
l = A("l")
j = A("j")
h = B("h")
n = B("n")
b = B("b")

g.t = j
i.z = h
d.z = h
l.t = j
j.t = l
h.z = b
n.z = b
b.z = d
assert d.z.z.z.z.txt == "h"