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

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

a = A("a")
d = B("d")
g = A("g")
j = A("j")
c = B("c")
k = B("k")
b = B("b")
m = A("m")
l = A("l")
f = A("f")

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

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

a = A("a")
d = B("d")
g = A("g")
j = A("j")
c = B("c")
k = B("k")
b = B("b")
m = A("m")
l = A("l")
f = A("f")

a.u = b
d.v = a
g.u = b
j.u = b
c.v = a
k.v = g
b.v = j
m.u = d
l.u = b
f.u = c
assert k.v.u.v.txt == "j"