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

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

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

b = A("b")
f = B("f")
e = C("e")
h = B("h")
j = C("j")
a = C("a")

b.p = a
f.s = j
f.w = h
f.o = b
e.w = h
h.s = e
h.w = f
h.o = b
j.w = f
a.w = f
assert b.p.w.s.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

b = A("b")
f = B("f")
e = C("e")
h = B("h")
j = C("j")
a = C("a")

b.p = a
f.s = j
f.w = h
f.o = b
e.w = h
h.s = e
h.w = f
h.o = b
j.w = f
a.w = f
assert b.p.w.s.w.w.w.txt == "f"