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

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

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

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

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

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

m.x = k
m.w = k
k.u = b
k.p = b
b.x = k
b.w = k
assert b.w.u.w.txt == "k"