#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long x, y, n;
    cin >> x >> y >> n;
    long long rem = n % x;
    if (rem == y) {
      cout << n << endl;
    } else if (rem < y) {
      n += (-rem + y);
      n -= x;
      cout << n << endl;
    } else if (rem > y) {
      n -= (rem - y);
      cout << n << endl;
    }
  }
}
