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

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

k = A("k")
d = B("d")
m = A("m")
b = A("b")
g = B("g")
n = A("n")
e = A("e")
c = A("c")

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

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

k = A("k")
d = B("d")
m = A("m")
b = A("b")
g = B("g")
n = A("n")
e = A("e")
c = A("c")

k.q = e
d.u = g
d.z = n
m.q = c
b.q = n
g.u = d
g.z = b
n.q = k
e.q = m
c.q = n
assert m.q.q.q.q.txt == "e"