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

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

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

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

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

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

j.q = m
i.v = g
i.y = m
m.v = i
m.y = g
l.q = m
g.v = i
g.y = m
assert j.q.v.v.txt == "g"