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

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

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

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

g = A("g")
m = B("m")
n = C("n")
e = D("e")
d = C("d")
j = C("j")

g.y = n
g.r = n
g.q = e
g.p = e
m.z = e
n.s = m
n.r = m
n.q = g
n.w = j
e.s = g
e.p = m
d.s = m
d.r = m
d.q = g
d.w = n
j.s = m
j.r = m
j.q = g
j.w = n
assert e.p.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.r: C = None
        self.q: D = None
        self.p: D = None
        self.txt = txt

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

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

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

g = A("g")
m = B("m")
n = C("n")
e = D("e")
d = C("d")
j = C("j")

g.y = n
g.r = n
g.q = e
g.p = e
m.z = e
n.s = m
n.r = m
n.q = g
n.w = j
e.s = g
e.p = m
d.s = m
d.r = m
d.q = g
d.w = n
j.s = m
j.r = m
j.q = g
j.w = n
assert e.p.z.s.txt == "g"