#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long x, y, n;
    cin >> x >> y >> n;
    int md = n % x;
    if (md == y) {
      cout << n << '\n';
      continue;
    }
    if (md > y) {
      long long diff = md - y;
      n -= diff;
      cout << n << '\n';
      continue;
    }
    if (md < y) {
      int div = n / x;
      div -= 1;
      int ans = ((x * div) + y);
      cout << ans << '\n';
      continue;
    }
  }
}
