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

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

l = A("l")
h = B("h")
j = A("j")
g = A("g")
i = A("i")
m = B("m")

l.s = m
l.v = g
h.v = m
j.s = m
j.v = l
g.s = m
g.v = i
i.s = m
i.v = g
m.v = h
assert h.v.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.v: A = None
        self.txt = txt

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

l = A("l")
h = B("h")
j = A("j")
g = A("g")
i = A("i")
m = B("m")

l.s = m
l.v = g
h.v = m
j.s = m
j.v = l
g.s = m
g.v = i
i.s = m
i.v = g
m.v = h
assert h.v.v.v.v.v.v.txt == "h"