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

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

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

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

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

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

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

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

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

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

h.y = m
a.w = g
a.r = h
g.x = a
g.z = m
g.s = m
g.p = c
l.z = h
l.u = h
l.q = m
c.y = m
i.z = h
i.u = h
i.q = g
m.x = a
m.z = g
m.s = g
m.p = c
assert h.y.z.p.y.z.txt == "g"