#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int solve(int x, int y, int n) {
  int hold = n % x;
  return n - (hold - y);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int x, y, n, hold;
    cin >> x >> y >> n;
    hold = n % x;
    if (hold < y) {
      cout << solve(x, y, n - (hold + 1)) << '\n';
    } else {
      cout << solve(x, y, n) << '\n';
    }
  }
  return 0;
}
