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

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

n = A("n")
d = B("d")
b = A("b")
a = A("a")
e = B("e")
g = B("g")
c = A("c")
h = A("h")
m = B("m")

n.z = m
d.q = e
d.v = h
b.z = g
a.z = e
e.q = m
e.v = n
g.q = e
g.v = b
c.z = d
h.z = e
m.q = g
m.v = c
assert e.q.q.v.z.q.q.v.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

n = A("n")
d = B("d")
b = A("b")
a = A("a")
e = B("e")
g = B("g")
c = A("c")
h = A("h")
m = B("m")

n.z = m
d.q = e
d.v = h
b.z = g
a.z = e
e.q = m
e.v = n
g.q = e
g.v = b
c.z = d
h.z = e
m.q = g
m.v = c
assert e.q.q.v.z.q.q.v.z.txt == "d"