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

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

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

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

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

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

k.v = l
k.r = d
g.u = d
a.u = g
j.u = g
l.v = e
l.r = g
f.v = k
f.r = a
i.v = k
i.r = j
e.v = l
e.r = g
d.u = g
assert k.r.u.u.u.txt == "g"