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

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

m = A("m")
g = B("g")
a = B("a")
c = B("c")
n = A("n")
j = B("j")
b = B("b")

m.z = n
g.u = c
a.u = j
c.u = j
n.z = m
j.u = c
b.u = c
assert c.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

m = A("m")
g = B("g")
a = B("a")
c = B("c")
n = A("n")
j = B("j")
b = B("b")

m.z = n
g.u = c
a.u = j
c.u = j
n.z = m
j.u = c
b.u = c
assert c.u.u.u.u.u.u.txt == "c"