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.z: B = None
        self.txt = txt

d = A("d")
j = B("j")
l = A("l")
n = B("n")
e = A("e")
a = B("a")
k = A("k")

d.u = k
j.q = a
j.z = n
l.u = e
n.q = j
n.z = a
e.u = d
a.q = j
a.z = j
k.u = d
assert n.z.q.z.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.z: B = None
        self.txt = txt

d = A("d")
j = B("j")
l = A("l")
n = B("n")
e = A("e")
a = B("a")
k = A("k")

d.u = k
j.q = a
j.z = n
l.u = e
n.q = j
n.z = a
e.u = d
a.q = j
a.z = j
k.u = d
assert n.z.q.z.txt == "n"