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

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

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

i = A("i")
n = B("n")
m = C("m")
f = A("f")
b = C("b")

i.p = b
i.s = n
n.o = i
m.w = f
m.x = b
m.p = n
f.p = m
f.s = n
b.w = i
b.x = m
b.p = n
assert f.s.o.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.s: B = None
        self.txt = txt

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

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

i = A("i")
n = B("n")
m = C("m")
f = A("f")
b = C("b")

i.p = b
i.s = n
n.o = i
m.w = f
m.x = b
m.p = n
f.p = m
f.s = n
b.w = i
b.x = m
b.p = n
assert f.s.o.s.o.s.txt == "n"