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

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

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

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

b.z = d
b.p = e
f.w = e
f.o = b
f.p = n
d.w = f
n.w = e
e.w = f
e.o = b
e.p = n
assert e.w.p.w.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.p: B = None
        self.txt = txt

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

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

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

b.z = d
b.p = e
f.w = e
f.o = b
f.p = n
d.w = f
n.w = e
e.w = f
e.o = b
e.p = n
assert e.w.p.w.p.w.txt == "e"