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

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

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

c = A("c")
i = B("i")
f = C("f")
h = A("h")
b = B("b")

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

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

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

c = A("c")
i = B("i")
f = C("f")
h = A("h")
b = B("b")

c.p = f
c.s = h
i.o = f
i.p = f
i.x = b
f.x = i
h.p = f
h.s = c
b.o = f
b.p = f
b.x = i
assert c.p.x.x.p.txt == "f"