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

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

a = A("a")
g = B("g")
e = A("e")
j = B("j")

a.v = j
g.s = a
e.v = g
j.s = e
assert g.s.v.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: A = None
        self.txt = txt

a = A("a")
g = B("g")
e = A("e")
j = B("j")

a.v = j
g.s = a
e.v = g
j.s = e
assert g.s.v.s.txt == "e"