Simultaneous solution of strong CP and flavor problems