Axionlike particles resolve the B→πK and g−2 anomalies