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

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

l = A("l")
i = B("i")
c = A("c")
j = B("j")
b = A("b")
f = B("f")
k = B("k")
n = A("n")
e = A("e")
m = B("m")

l.u = i
i.v = j
i.r = n
c.u = j
j.v = m
j.r = c
b.u = j
f.v = j
f.r = c
k.v = f
k.r = e
n.u = j
e.u = m
m.v = i
m.r = e
assert k.r.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: B = None
        self.r: A = None
        self.txt = txt

l = A("l")
i = B("i")
c = A("c")
j = B("j")
b = A("b")
f = B("f")
k = B("k")
n = A("n")
e = A("e")
m = B("m")

l.u = i
i.v = j
i.r = n
c.u = j
j.v = m
j.r = c
b.u = j
f.v = j
f.r = c
k.v = f
k.r = e
n.u = j
e.u = m
m.v = i
m.r = e
assert k.r.u.v.txt == "i"