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

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

f = A("f")
a = B("a")
k = B("k")

f.o = k
a.v = f
a.x = f
k.v = f
k.x = f
assert k.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

f = A("f")
a = B("a")
k = B("k")

f.o = k
a.v = f
a.x = f
k.v = f
k.x = f
assert k.x.o.x.txt == "f"