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

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

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

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

h = A("h")
g = B("g")
a = C("a")
f = D("f")
e = A("e")
m = B("m")
k = A("k")
d = C("d")
i = D("i")

h.r = d
g.p = a
a.x = m
a.s = d
f.p = g
f.z = i
f.w = e
e.r = a
m.p = d
k.r = a
d.x = m
d.s = a
i.p = g
i.z = f
i.w = e
assert h.r.x.p.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
a = C("a")
f = D("f")
e = A("e")
m = B("m")
k = A("k")
d = C("d")
i = D("i")

h.r = d
g.p = a
a.x = m
a.s = d
f.p = g
f.z = i
f.w = e
e.r = a
m.p = d
k.r = a
d.x = m
d.s = a
i.p = g
i.z = f
i.w = e
assert h.r.x.p.x.p.txt == "d"