class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.w: 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.p: C = None
        self.o: B = None
        self.u: C = None
        self.txt = txt

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

k.p = h
k.w = f
f.o = k
d.p = h
d.u = h
d.o = f
h.p = d
h.u = d
h.o = f
assert f.o.p.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.w: 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.p: C = None
        self.o: B = None
        self.u: C = None
        self.txt = txt

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

k.p = h
k.w = f
f.o = k
d.p = h
d.u = h
d.o = f
h.p = d
h.u = d
h.o = f
assert f.o.p.o.o.txt == "k"