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

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

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

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

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

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

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

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

g.y = m
c.w = g
c.y = g
c.o = g
m.o = g
m.q = c
assert c.o.y.q.txt == "c"