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

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

m = A("m")
e = B("e")
b = A("b")
k = A("k")
f = B("f")
l = B("l")

m.x = k
m.r = l
e.x = l
e.v = b
b.x = m
b.r = l
k.x = b
k.r = e
f.x = l
f.v = k
l.x = f
l.v = k
assert b.r.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: B = None
        self.txt = txt

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

m = A("m")
e = B("e")
b = A("b")
k = A("k")
f = B("f")
l = B("l")

m.x = k
m.r = l
e.x = l
e.v = b
b.x = m
b.r = l
k.x = b
k.r = e
f.x = l
f.v = k
l.x = f
l.v = k
assert b.r.x.v.txt == "k"