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

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

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

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

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

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

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

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

f.r = m
f.o = m
a.s = m
a.r = m
m.q = f
assert a.s.q.r.txt == "m"