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

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

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

n = A("n")
k = B("k")
d = C("d")
h = A("h")

n.w = k
k.p = d
k.o = d
k.t = n
d.p = k
d.q = k
d.s = k
h.w = k
assert d.q.p.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

n = A("n")
k = B("k")
d = C("d")
h = A("h")

n.w = k
k.p = d
k.o = d
k.t = n
d.p = k
d.q = k
d.s = k
h.w = k
assert d.q.p.q.t.txt == "n"