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

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

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

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

a.s = m
a.w = m
a.q = f
m.o = a
m.x = a
f.z = a
f.x = a
f.q = a
assert a.q.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.q: C = None
        self.w: B = None
        self.txt = txt

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

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

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

a.s = m
a.w = m
a.q = f
m.o = a
m.x = a
f.z = a
f.x = a
f.q = a
assert a.q.z.s.txt == "m"