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

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

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

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

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

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

m.y = f
f.p = g
f.v = m
g.p = f
g.v = m
assert m.y.v.y.txt == "f"