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

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

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

c = A("c")
e = B("e")
m = C("m")

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

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

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

c = A("c")
e = B("e")
m = C("m")

c.r = m
c.y = m
e.y = m
e.q = c
e.s = c
m.s = c
m.w = c
m.o = e
assert c.y.o.q.txt == "c"