#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long x, y, n;
    cin >> x >> y >> n;
    long long res = n / x * x;
    res += y;
    while (res <= n) res += x;
    cout << res - x << '\n';
  }
}
