#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long x, y, n;
    cin >> x >> y >> n;
    long long res = n % x;
    long long res2 = (n - res - (x - y));
    if (res == y)
      cout << n << "\n";
    else if (res2 + x > n)
      cout << res2 << "\n";
    else
      cout << res2 + x << "\n";
  }
  return 0;
}
