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

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

i = A("i")
g = B("g")
f = A("f")

i.s = f
i.v = g
g.x = i
f.s = i
f.v = g
assert i.v.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.v: B = None
        self.txt = txt

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

i = A("i")
g = B("g")
f = A("f")

i.s = f
i.v = g
g.x = i
f.s = i
f.v = g
assert i.v.x.s.txt == "f"