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

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

class C:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: D = None
        self.t: B = None
        self.o: A = None
        self.txt = txt

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

f = A("f")
h = B("h")
d = C("d")
m = D("m")
i = C("i")
j = A("j")

f.s = m
f.z = j
f.w = j
f.o = d
h.p = m
d.z = i
d.y = m
d.t = h
d.o = j
m.x = h
i.z = d
i.y = m
i.t = h
i.o = f
j.s = m
j.z = f
j.w = f
j.o = d
assert h.p.x.p.x.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.z: A = None
        self.w: A = None
        self.o: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: D = None
        self.t: B = None
        self.o: A = None
        self.txt = txt

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

f = A("f")
h = B("h")
d = C("d")
m = D("m")
i = C("i")
j = A("j")

f.s = m
f.z = j
f.w = j
f.o = d
h.p = m
d.z = i
d.y = m
d.t = h
d.o = j
m.x = h
i.z = d
i.y = m
i.t = h
i.o = f
j.s = m
j.z = f
j.w = f
j.o = d
assert h.p.x.p.x.p.x.txt == "h"