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

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

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

l = A("l")
c = B("c")
i = C("i")
d = A("d")

l.q = d
l.o = d
c.z = i
c.w = i
i.u = c
i.w = c
d.q = l
d.o = l
assert d.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: A = None
        self.txt = txt

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

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

l = A("l")
c = B("c")
i = C("i")
d = A("d")

l.q = d
l.o = d
c.z = i
c.w = i
i.u = c
i.w = c
d.q = l
d.o = l
assert d.o.o.o.o.txt == "d"