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

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

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

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

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

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

l.s = g
f.v = g
g.v = f
assert g.v.v.v.txt == "f"