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

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

j = A("j")
i = B("i")
l = B("l")
d = B("d")
a = A("a")
e = B("e")
g = A("g")
m = B("m")
n = B("n")
b = A("b")

j.p = g
j.q = l
i.v = b
i.w = l
l.v = b
l.w = m
d.v = a
d.w = n
a.p = g
a.q = e
e.v = b
e.w = m
g.p = a
g.q = n
m.v = b
m.w = l
n.v = g
n.w = m
b.p = a
b.q = d
assert e.v.q.v.q.v.p.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.q: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
l = B("l")
d = B("d")
a = A("a")
e = B("e")
g = A("g")
m = B("m")
n = B("n")
b = A("b")

j.p = g
j.q = l
i.v = b
i.w = l
l.v = b
l.w = m
d.v = a
d.w = n
a.p = g
a.q = e
e.v = b
e.w = m
g.p = a
g.q = n
m.v = b
m.w = l
n.v = g
n.w = m
b.p = a
b.q = d
assert e.v.q.v.q.v.p.q.w.txt == "m"