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

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

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

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

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

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

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