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

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

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

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

f.y = a
a.q = f
n.q = f
assert n.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

f.y = a
a.q = f
n.q = f
assert n.q.y.q.txt == "f"