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

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

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

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

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

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

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

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

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

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

j.q = l
j.w = l
n.q = j
n.w = m
l.z = a
l.p = n
g.p = n
g.y = n
g.w = a
g.s = l
a.p = n
a.y = n
a.w = g
a.s = l
m.q = j
m.w = n
assert j.q.p.w.txt == "m"