#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e6 + 5;
const int MAXN = 105;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long x, y, z;
    cin >> x >> y >> z;
    if ((z % x) != y) {
      long long rm = z % x;
      if (rm > y)
        z -= rm - y;
      else {
        z -= rm;
        z -= x - y;
      }
    }
    z = max(0ll, z);
    cout << z << endl;
  }
}
