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

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

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

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

m = A("m")
g = B("g")
j = C("j")
c = D("c")
a = A("a")
l = C("l")
d = C("d")

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

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

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

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

m = A("m")
g = B("g")
j = C("j")
c = D("c")
a = A("a")
l = C("l")
d = C("d")

m.p = a
m.u = a
m.q = a
m.s = d
g.w = c
j.v = d
j.w = m
j.z = c
c.s = d
c.r = g
a.p = m
a.u = m
a.q = m
a.s = l
l.v = j
l.w = m
l.z = c
d.v = l
d.w = a
d.z = c
assert g.w.r.w.s.z.s.txt == "d"