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

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

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

k = A("k")
n = B("n")
f = C("f")
b = B("b")
d = C("d")

k.p = b
n.t = b
n.o = k
f.y = n
f.s = d
f.x = d
b.t = n
b.o = k
d.y = n
d.s = f
d.x = f
assert n.t.o.p.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

k = A("k")
n = B("n")
f = C("f")
b = B("b")
d = C("d")

k.p = b
n.t = b
n.o = k
f.y = n
f.s = d
f.x = d
b.t = n
b.o = k
d.y = n
d.s = f
d.x = f
assert n.t.o.p.t.o.txt == "k"