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

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

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

m = A("m")
b = B("b")
f = C("f")
c = C("c")

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

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

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

m = A("m")
b = B("b")
f = C("f")
c = C("c")

m.w = b
m.r = c
m.o = c
b.r = m
f.x = c
f.o = b
f.q = b
c.x = f
c.o = b
c.q = b
assert b.r.r.x.txt == "f"