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

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

k = A("k")
a = B("a")
d = B("d")
n = B("n")
h = B("h")
j = A("j")
g = B("g")
f = B("f")

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

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

k = A("k")
a = B("a")
d = B("d")
n = B("n")
h = B("h")
j = A("j")
g = B("g")
f = B("f")

k.u = j
a.q = h
a.u = d
d.q = a
d.u = g
n.q = f
n.u = a
h.q = d
h.u = n
j.u = k
g.q = f
g.u = d
f.q = n
f.u = a
assert a.u.u.q.u.txt == "a"