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

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

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

h.z = l
a.w = l
a.t = l
f.w = h
f.t = h
e.w = h
e.t = l
l.z = h
g.w = h
g.t = l
m.w = l
m.t = h
assert a.t.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

h.z = l
a.w = l
a.t = l
f.w = h
f.t = h
e.w = h
e.t = l
l.z = h
g.w = h
g.t = l
m.w = l
m.t = h
assert a.t.z.z.z.z.z.z.txt == "l"