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

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

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

m = A("m")
d = B("d")
b = C("b")
n = B("n")

m.u = n
m.q = b
d.o = n
d.x = n
d.z = m
b.o = d
n.o = d
n.x = d
n.z = m
assert b.o.o.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.q: C = None
        self.txt = txt

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

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

m = A("m")
d = B("d")
b = C("b")
n = B("n")

m.u = n
m.q = b
d.o = n
d.x = n
d.z = m
b.o = d
n.o = d
n.x = d
n.z = m
assert b.o.o.x.z.txt == "m"