Ruling backs Montana's right to Wyoming water for reservoir