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

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

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

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

h = A("h")
a = B("a")
m = C("m")
b = D("b")
g = C("g")
i = B("i")
c = A("c")
l = D("l")
e = C("e")

h.w = e
h.o = c
a.x = l
a.p = i
a.o = c
m.x = l
b.p = l
b.r = l
b.z = i
g.x = l
i.x = l
i.p = a
i.o = c
c.w = m
c.o = h
l.p = b
l.r = b
l.z = a
e.x = b
assert b.p.r.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.o: A = None
        self.txt = txt

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

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

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

h = A("h")
a = B("a")
m = C("m")
b = D("b")
g = C("g")
i = B("i")
c = A("c")
l = D("l")
e = C("e")

h.w = e
h.o = c
a.x = l
a.p = i
a.o = c
m.x = l
b.p = l
b.r = l
b.z = i
g.x = l
i.x = l
i.p = a
i.o = c
c.w = m
c.o = h
l.p = b
l.r = b
l.z = a
e.x = b
assert b.p.r.z.p.txt == "a"