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

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

f = A("f")
c = B("c")
b = A("b")
e = B("e")
g = B("g")
a = B("a")
d = A("d")
l = B("l")
k = A("k")
j = B("j")

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

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

f = A("f")
c = B("c")
b = A("b")
e = B("e")
g = B("g")
a = B("a")
d = A("d")
l = B("l")
k = A("k")
j = B("j")

f.r = l
c.z = g
b.r = g
e.z = l
g.z = a
a.z = g
d.r = g
l.z = c
k.r = j
j.z = a
assert f.r.z.z.z.z.z.z.z.z.txt == "g"