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