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

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

c = A("c")
l = B("l")
d = A("d")
m = A("m")
e = B("e")
g = B("g")
n = A("n")
f = A("f")

c.q = d
l.z = g
d.q = c
m.q = d
e.z = g
g.z = e
n.q = m
f.q = c
assert e.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

c = A("c")
l = B("l")
d = A("d")
m = A("m")
e = B("e")
g = B("g")
n = A("n")
f = A("f")

c.q = d
l.z = g
d.q = c
m.q = d
e.z = g
g.z = e
n.q = m
f.q = c
assert e.z.z.z.z.z.txt == "g"