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

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

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

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

h = A("h")
a = B("a")
b = C("b")
c = D("c")
m = A("m")

h.o = a
h.s = a
h.w = a
h.p = m
a.p = h
b.z = h
c.x = a
m.o = a
m.s = a
m.w = a
m.p = h
assert a.p.w.p.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.p: A = None
        self.s: B = None
        self.w: B = None
        self.txt = txt

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

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

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

h = A("h")
a = B("a")
b = C("b")
c = D("c")
m = A("m")

h.o = a
h.s = a
h.w = a
h.p = m
a.p = h
b.z = h
c.x = a
m.o = a
m.s = a
m.w = a
m.p = h
assert a.p.w.p.p.w.txt == "a"