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

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

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

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

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

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

k.y = m
b.y = k
b.v = m
e.y = k
e.v = i
m.y = k
m.v = e
i.y = l
i.v = m
l.y = i
assert e.v.v.v.txt == "e"