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

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

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

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

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

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

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

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

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

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

g.s = n
g.q = e
g.p = m
i.q = b
i.z = m
b.u = i
b.r = g
m.q = g
m.s = g
e.s = b
e.q = g
e.p = m
d.q = b
d.z = m
n.u = d
n.r = g
assert i.q.u.q.r.p.txt == "m"