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.o: A = None
        self.z: B = None
        self.txt = txt

n = A("n")
g = B("g")
f = B("f")
l = B("l")

n.w = g
n.p = g
g.o = n
g.z = l
f.o = n
f.z = g
l.o = n
l.z = f
assert f.z.o.p.o.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.o: A = None
        self.z: B = None
        self.txt = txt

n = A("n")
g = B("g")
f = B("f")
l = B("l")

n.w = g
n.p = g
g.o = n
g.z = l
f.o = n
f.z = g
l.o = n
l.z = f
assert f.z.o.p.o.txt == "n"