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

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

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

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

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

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

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

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

m.r = a
m.o = n
n.o = a
a.t = n
a.q = f
f.t = n
f.q = a
assert a.t.o.q.t.txt == "n"