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

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

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

l = A("l")
e = B("e")
b = C("b")
c = A("c")

l.w = b
l.q = c
e.x = c
b.r = l
b.o = l
b.y = e
c.w = b
c.q = l
assert b.y.x.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.q: A = None
        self.txt = txt

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

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

l = A("l")
e = B("e")
b = C("b")
c = A("c")

l.w = b
l.q = c
e.x = c
b.r = l
b.o = l
b.y = e
c.w = b
c.q = l
assert b.y.x.w.y.txt == "e"