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

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

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

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

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

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

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

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

f.q = n
b.t = n
a.r = n
a.x = n
n.r = a
n.x = a
assert b.t.x.x.txt == "n"