#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y, k, mod = 0, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    mod = 0;
    cin >> x >> y >> k;
    mod = k % x;
    if (mod - y >= 0) {
      mod -= y;
      cout << k - mod << "\n";
    } else {
      sum = k % x;
      sum = k - sum - 1;
      mod = sum % x;
      ++mod;
      mod -= y;
      cout << sum - mod + 1 << "\n";
    }
  }
}
