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

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

h = A("h")
l = B("l")
a = A("a")
b = B("b")
n = B("n")
k = B("k")
d = B("d")
m = A("m")

h.q = m
h.u = b
l.v = k
l.x = m
a.q = h
a.u = n
b.v = l
b.x = a
n.v = b
n.x = m
k.v = d
k.x = m
d.v = n
d.x = a
m.q = a
m.u = d
assert m.u.v.v.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.u: B = None
        self.txt = txt

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

h = A("h")
l = B("l")
a = A("a")
b = B("b")
n = B("n")
k = B("k")
d = B("d")
m = A("m")

h.q = m
h.u = b
l.v = k
l.x = m
a.q = h
a.u = n
b.v = l
b.x = a
n.v = b
n.x = m
k.v = d
k.x = m
d.v = n
d.x = a
m.q = a
m.u = d
assert m.u.v.v.x.q.txt == "h"