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

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

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

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

a.u = f
n.p = a
d.t = n
d.w = n
d.q = f
f.t = n
f.w = n
f.q = d
assert f.w.p.u.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

a.u = f
n.p = a
d.t = n
d.w = n
d.q = f
f.t = n
f.w = n
f.q = d
assert f.w.p.u.t.txt == "n"