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

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

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

d = A("d")
m = B("m")
a = C("a")

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

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

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

d = A("d")
m = B("m")
a = C("a")

d.o = a
d.q = m
m.z = d
m.u = a
m.q = a
a.r = m
a.o = d
assert d.q.q.o.txt == "d"