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

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

e = A("e")
g = B("g")
k = B("k")
h = A("h")
l = A("l")
f = B("f")
b = A("b")
d = A("d")
j = A("j")
m = B("m")

e.p = g
e.z = b
g.q = d
k.q = h
h.p = m
h.z = d
l.p = g
l.z = h
f.q = h
b.p = k
b.z = j
d.p = m
d.z = e
j.p = f
j.z = l
m.q = b
assert e.p.q.z.p.q.z.z.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.z: A = None
        self.txt = txt

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

e = A("e")
g = B("g")
k = B("k")
h = A("h")
l = A("l")
f = B("f")
b = A("b")
d = A("d")
j = A("j")
m = B("m")

e.p = g
e.z = b
g.q = d
k.q = h
h.p = m
h.z = d
l.p = g
l.z = h
f.q = h
b.p = k
b.z = j
d.p = m
d.z = e
j.p = f
j.z = l
m.q = b
assert e.p.q.z.p.q.z.z.p.q.txt == "h"