#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9;
const double PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};
void debug() { cerr << "\n"; }
template <typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
  cerr << a << " ";
  debug(b...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long x, y, n;
    cin >> x >> y >> n;
    if (y == 0) y = x;
    long long l = 0, r = 1e9 * 1ll, ans = 0;
    while (l <= r) {
      long long mid = l + (r - l) / 2;
      if (mid * y <= n) {
        ans = mid * y;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    if (ans + (y - (ans % x)) <= n)
      ans += (y - (ans % x));
    else {
      long long d = (y - (ans % x));
      ans -= x;
      ans += d;
    }
    cout << ans << "\n";
  }
  return 0;
}
