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

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

g = A("g")
d = B("d")
f = A("f")
i = A("i")
k = A("k")
n = A("n")
l = B("l")
b = A("b")
j = B("j")
a = B("a")

g.u = b
g.z = l
d.v = a
f.u = n
f.z = a
i.u = k
i.z = j
k.u = i
k.z = a
n.u = f
n.z = a
l.v = j
b.u = k
b.z = d
j.v = d
a.v = j
assert d.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.z: B = None
        self.txt = txt

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

g = A("g")
d = B("d")
f = A("f")
i = A("i")
k = A("k")
n = A("n")
l = B("l")
b = A("b")
j = B("j")
a = B("a")

g.u = b
g.z = l
d.v = a
f.u = n
f.z = a
i.u = k
i.z = j
k.u = i
k.z = a
n.u = f
n.z = a
l.v = j
b.u = k
b.z = d
j.v = d
a.v = j
assert d.v.v.v.v.txt == "a"