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

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

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

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

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

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

a.p = m
m.x = a
m.o = a
k.x = a
k.o = a
assert k.x.p.x.txt == "a"