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

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

j = A("j")
l = B("l")
k = A("k")
g = B("g")
m = B("m")

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

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

j = A("j")
l = B("l")
k = A("k")
g = B("g")
m = B("m")

j.v = m
l.s = g
k.v = m
g.s = m
m.s = l
assert g.s.s.s.s.s.txt == "l"