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

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

i = A("i")
m = B("m")
l = B("l")
c = B("c")
h = B("h")
b = A("b")
f = A("f")
d = B("d")
e = B("e")
g = B("g")

i.z = d
m.r = b
l.r = f
c.r = i
h.r = i
b.z = l
f.z = g
d.r = f
e.r = b
g.r = f
assert c.r.z.r.z.r.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

i = A("i")
m = B("m")
l = B("l")
c = B("c")
h = B("h")
b = A("b")
f = A("f")
d = B("d")
e = B("e")
g = B("g")

i.z = d
m.r = b
l.r = f
c.r = i
h.r = i
b.z = l
f.z = g
d.r = f
e.r = b
g.r = f
assert c.r.z.r.z.r.z.r.z.txt == "g"