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

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

h = A("h")
g = B("g")
k = B("k")
n = A("n")
d = A("d")
a = A("a")
b = B("b")
i = B("i")
m = A("m")
j = B("j")

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

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

h = A("h")
g = B("g")
k = B("k")
n = A("n")
d = A("d")
a = A("a")
b = B("b")
i = B("i")
m = A("m")
j = B("j")

h.u = b
g.q = i
g.x = d
k.q = i
k.x = d
n.u = g
d.u = j
a.u = k
b.q = g
b.x = m
i.q = k
i.x = a
m.u = g
j.q = b
j.x = m
assert g.x.u.q.txt == "b"