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

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

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

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

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

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

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

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

n.q = a
a.o = n
a.p = b
b.z = f
b.q = f
f.q = a
assert f.q.p.q.q.txt == "a"