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

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

k = A("k")
b = B("b")
n = A("n")
f = B("f")

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

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

k = A("k")
b = B("b")
n = A("n")
f = B("f")

k.w = b
k.x = b
b.p = f
b.y = k
n.w = f
n.x = f
f.p = b
f.y = n
assert b.p.p.y.x.txt == "b"