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

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

f = A("f")
e = B("e")
k = A("k")
g = A("g")
b = B("b")

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

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

f = A("f")
e = B("e")
k = A("k")
g = A("g")
b = B("b")

f.w = e
f.p = e
e.x = k
k.w = e
k.p = e
g.w = e
g.p = b
b.x = k
assert b.x.w.x.txt == "k"