#include<bits/stdc++.h>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int N,A,B; cin>>N>>A>>B;
    cout<<N-A+B<<endl;
}

//author: hitch_hiker42;
#include<bits/stdc++.h>
using namespace std;

//solution:
#define int int64_t

auto gcd(int a, int b) {
  if(!b) return make_tuple(a, 1LL, 0LL);
  auto [g, x, y] = gcd(b, a % b);
  return make_tuple(g, y, x - (a / b) * y);
}

int linsolver(int a, int b, int m) {
  if(b % __gcd(a, m)) return -1;
  auto [g, x, y] = gcd(a, m);
  a /= g, b /= g, m /= g;
  return ((b * x % m) + m) % m;
}

void hike() {
  int n, s, k; cin >> n >> s >> k, s = n - s;
  cout << linsolver(k, s, n) << "\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  int t = 1; cin >> t;
  while(t--) hike();
  return 0;
} //farewell, until we meet again..