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

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

j = A("j")
m = B("m")
b = B("b")

j.x = b
j.v = m
m.v = j
m.p = j
b.v = j
b.p = j
assert j.x.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.v: B = None
        self.txt = txt

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

j = A("j")
m = B("m")
b = B("b")

j.x = b
j.v = m
m.v = j
m.p = j
b.v = j
b.p = j
assert j.x.v.x.txt == "b"