You are given three integers $x, y$ and $n$. Your task is to find the maximum integer $k$ such that $0 \le k \le n$ that $k \bmod x = y$, where $\bmod$ is modulo operation. Many programming languages use percent operator % to implement it.

In other words, with given $x, y$ and $n$ you need to find the maximum possible integer from $0$ to $n$ that has the remainder $y$ modulo $x$.

You have to answer $t$ independent test cases. It is guaranteed that such $k$ exists for each test case.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 5 \cdot 10^4$) — the number of test cases. The next $t$ lines contain test cases.

The only line of the test case contains three integers $x, y$ and $n$ ($2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$).

It can be shown that such $k$ always exists under the given constraints.


-----Output-----

For each test case, print the answer — maximum non-negative integer $k$ such that $0 \le k \le n$ and $k \bmod x = y$. It is guaranteed that the answer always exists.


-----Example-----
Input
7
7 5 12345
5 0 4
10 5 15
17 8 54321
499999993 9 1000000000
10 5 187
2 0 999999999

Output
12339
0
15
54306
999999995
185
999999998



-----Note-----

In the first test case of the example, the answer is $12339 = 7 \cdot 1762 + 5$ (thus, $12339 \bmod 7 = 5$). It is obvious that there is no greater integer not exceeding $12345$ which has the remainder $5$ modulo $7$.

Difficulty: EASY

Solutions:
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	k = (n - y) // x
	print(x * k + y)


t = int(input())
for i in range(0, t):
	(x, y, n) = [int(x) for x in input().split()]
	if n % x == y:
		print(n)
	elif n % x < y:
		q = n % x
		print(n + abs(y - q) - x)
	else:
		q = n % x
		print(n - abs(y - q))


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	base = n // x * x
	if base + y <= n and (base + y) % x == y:
		print(base + y)
	else:
		print(base - x + y)


from sys import stdin, stdout
q = int(input())
for i in range(q):
	(x, y, n) = list(map(int, stdin.readline().split()))
	rem = n % x
	if rem > y:
		n -= rem - y
	elif rem < y:
		n -= rem
		n -= x - y
	print(n)


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	g = n // x
	if g * x + y <= n:
		print(g * x + y)
	else:
		print((g - 1) * x + y)


T = int(input())
for t in range(T):
	(x, y, n) = (int(i) for i in input().split())
	a = n % x
	if a == y:
		print(n)
	elif n - a + y <= n:
		print(n - a + y)
	else:
		print(n - a + y - x)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a == y:
		print(n)
	elif a > y:
		z = a - y
		print(n - z)
	else:
		b = x - y
		print(n - a - b)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	num = n
	rem = n % x
	if rem == y:
		print(num)
	elif rem < y:
		num = num - rem - (x - y)
		print(num)
	else:
		num = num - (rem - y)
		print(num)


t = int(input())
for s in range(t):
	(x, y, n) = map(int, input().split())
	ans = n % x
	d = x - y
	if ans == y:
		print(n)
	elif ans > y:
		print(n - ans + y)
	else:
		g = n - ans
		g = g - d
		if g < 0:
			print(0)
		else:
			print(g)


T = int(input())
while T > 0:
	(a, b, n) = map(int, input().split())
	if b == 0:
		print(int(n / a) * a)
	elif n % a < b:
		k = (int(n / a) - 1) * a + b
		print(k)
	elif n % a > b:
		k = int(n / a) * a + b
		print(k)
	else:
		print(n)
	T -= 1


test_cases = int(input())
for i in range(test_cases):
	(x, y, n) = map(int, input().split())
	g = n % x
	if g == y:
		print(n)
	elif g > y:
		print(n - g + y)
	elif g < y:
		print(n - g - x + y)


T = int(input())
for t in range(T):
	(x, y, n) = map(int, input().split())
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = c % a
	if d >= b:
		print(c - (d - b))
	else:
		print(c - (d + a - b))


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	r = n % x
	if r >= y:
		print(n - (r - y))
	else:
		print(n - (r + (x - y)))


def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	(x, y, n) = read_list()
	t = n // x
	if t * x + y > n:
		t -= 1
	print(t * x + y)


def f(n, x, y):
	for i in range((n - y) // x, -1, -1):
		if (i * x + y) % x == y:
			return i * x + y
	return 0
data_set_count = int(input())
size = [0] * data_set_count
ret = []
for i in range(data_set_count):
	temp = list(map(int, input().split()))
	x = temp[0]
	y = temp[1]
	n = temp[2]
	ret.append(f(n, x, y))
for i in range(data_set_count):
	print(ret[i])


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	print(n - (n - y) % x)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	(a, b, n) = ip()
	no = a * (n // a)
	if no + b <= n:
		print(no + b)
	else:
		print(no - a + b)


from sys import stdin
import math
A = int(stdin.readline())
for t in range(0, A):
	B = list(map(int, stdin.readline().split()))
	x = B[0]
	y = B[1]
	n = B[2]
	ans = n // x * x + y
	if ans > n:
		print(ans - x)
	else:
		print(ans)


N = int(input())
for i in range(N):
	data = input()
	data_list = data.split()
	x = int(data_list[0])
	y = int(data_list[1])
	n = int(data_list[2])
	num = n // x
	output = num * x + y
	if output > n:
		output = (num - 1) * x + y
	print(output)


for s in [*open(0)][1:]:
	(x, y, n) = map(int, s.split())
	print(n - (n - y) % x)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	delta = y - int(n % x)
	if delta > 0:
		delta -= x
	print(n + delta)


import sys
infile = sys.stdin
next(infile)
for line in infile:
	l = list(map(int, line.split()))
	r = l[2] % l[0]
	if r - l[1] > 0:
		l[2] = l[2] - (r - l[1])
	elif r - l[1] < 0:
		l[2] = l[2] - r + l[1] - l[0]
	else:
		l[2] = l[2]
	print(str(l[2]))


for _ in range(int(input())):
	(x, y, n) = [int(i) for i in input().split()]
	mx = n // x
	if mx * x + y <= n:
		print(mx * x + y)
	else:
		print((mx - 1) * x + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		mx = -1
		z = n % x
		if n - z + y <= n:
			mx = n - z + y
		if n + (x - z) - 2 * x + y <= n:
			mx = max(mx, n + (x - z) - 2 * x + y)
		print(mx)


def solve(x, y, n):
	if n % x == y:
		return n
	temp = n % x
	if temp > y:
		return n - (temp - y)
	else:
		return n - (temp + (x - y))
cases = int(input())
for _ in range(cases):
	(x, y, n) = map(int, input().split())
	ans = solve(x, y, n)
	print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	q = n % x
	if q == y:
		print(n)
	elif q > y:
		print(n - (q - y))
	else:
		print(n - q - (x - y))


from math import ceil
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	if y == 0:
		if n % x == 0:
			print(n)
		else:
			print(n - n % x)
	else:
		ans1 = n - n % x
		ans2 = ans1 - x + y
		ans3 = ans1 + y
		if max(ans2, ans3) == ans3:
			if ans3 <= n:
				print(ans3)
			else:
				print(ans2)
		elif max(ans2, ans3) == ans2:
			if ans2 <= n:
				print(ans2)
			else:
				print(ans3)


test = int(input())
temp = test
my_list = []

def print_func():
	for n in my_list:
		print(n)
while test != 0:
	(x, y, n) = [int(x) for x in input().split()]
	rem = (n - y) % x
	if rem == 0:
		k = n
	else:
		k = n - rem
	string = str(k)
	my_list.append(string)
	test -= 1
print_func()


t = int(input())
ar = []
for i in range(t):
	(x, y, n) = map(int, input().split())
	k = n + 1
	if n < x:
		k = y
	elif n == x:
		if y == 0:
			k = x
		else:
			k = y
	else:
		c = n // x
		while k > n:
			k = c * x + y
			c -= 1
	ar.append(k)
for i in ar:
	print(i)


a = int(input())
for i in range(a):
	(x, y, n) = map(int, input().split())
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	rem = n % x
	if rem == y:
		print(n)
	elif y < rem:
		print(n - (rem - y))
	else:
		print(n - rem - (x - 1 - y) - 1)


for i in range(int(input())):
	(x, y, n) = list(map(int, input().split(' ')))
	print(n - (n - y) % x)


for fi in range(int(input())):
	x = input().split(' ')
	print(int(x[0]) * ((int(x[2]) - int(x[1])) // int(x[0])) + int(x[1]))


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n % x
	ans = n
	if a >= y:
		ans -= a - y
	else:
		ans -= x - (y - a)
	print(ans)


z = int(input())
for i in range(z):
	a = input().split()
	for i in range(len(a)):
		a[i] = int(a[i])
	x = a[0]
	y = a[1]
	n = a[2]
	r = n % x
	if r == y:
		print(n)
	elif r < y:
		print(n - r - (x - y))
	else:
		print(n - (r - y))


test = int(input())
for _ in range(test):
	(x, y, n) = map(int, input().split())
	k = n % x
	if k < y:
		p = x - y
		print(n - k - x + y)
	elif k == y:
		print(n)
	else:
		print(n - k + y)


n1 = int(input())
for i in range(n1):
	nums = [int(n) for n in input().split()]
	x = nums[0]
	y = nums[1]
	n = nums[2]
	count = n // x
	answer = x * count + y
	if answer > n:
		answer -= x
	print(answer)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	q = (n - y) // x
	print(y + x * q)


import sys
input = sys.stdin.buffer.readline

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	(x, y, n) = I()
	d = n % x
	if d >= y:
		ans = n - d + y
	else:
		ans = n - x + (y - d)
	if ans < 0:
		print(-1)
	else:
		print(ans)


t = int(input())
while t > 0:
	(x, y, n) = map(int, input().split())
	ans = int(n / x)
	ans = ans * x + y
	if ans <= n:
		print(ans)
	else:
		print((int(n / x) - 1) * x + y)
	t = t - 1


t = int(input())
p = 1
while p <= t:
	(x, y, z) = [int(x) for x in input().split()]
	m = z / x
	o = int(m) * x
	if o + y <= z:
		print(o + y)
	else:
		print(o - (x - y))
	p += 1


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a == y:
		print(n)
	elif a < y:
		n += y - a
		n -= x
		print(n)
	else:
		n -= a - y
		print(n)


T = int(input())
for test in range(T):
	(x, y, n) = map(int, input().split())
	m = int((n - y) / x)
	k = m * x + y
	print(k)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	(x, y, n) = mi()
	print((n - y) // x * x + y)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
T = inp()
tests = []
for _ in range(T):
	tests.append(inlt())
for test in tests:
	(x, y, n) = test
	curr = n % x
	diff = curr - y
	if diff == 0:
		print(n)
	elif diff > 0:
		print(max(0, n - diff))
	else:
		print(max(0, n - diff - x))


tst = int(input())
for i in range(tst):
	(a, b, n) = map(int, input().split())
	k = n % a
	if k > b:
		print(n - (k - b))
	elif k == b:
		print(n)
	else:
		print(n - (a - (b - k)))


t = int(input())
for i in range(t):
	(n, k, s) = map(int, input().split())
	if s % n != k:
		c = s % n
		ans = s - c + k
		if ans > s:
			ans -= n
		print(ans)
	else:
		print(s)


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	f = n // x
	while f * x + y > n:
		f -= 1
	print(f * x + y)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	m = n % x
	if n % x == y:
		print(n)
	elif m > y:
		print(n - m + y)
	else:
		print(n - m - x + y)


T = int(input())
for _ in range(T):
	(x, y, n) = list(map(int, input().split()))
	ans = n // x * x + y
	while ans > n:
		ans -= x
	print(ans)


test_cases = int(input())
for t in range(test_cases):
	(x, y, n) = list(map(int, input().split()))
	y_prime = n % x
	if y_prime == y:
		print(n)
	if y_prime > y:
		print(n + y - y_prime)
	if y_prime < y:
		print(n - y_prime - x + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	ans = n % x
	if ans - y > 0:
		ans = n - (ans - y)
	elif ans - y < 0:
		ans = n - n % x - (x - y)
	else:
		ans = n
	print(ans)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	rem = n % x
	if n % x == y:
		print(n)
	elif rem > y:
		print(int(n - (rem - y)))
	elif rem < y:
		sub = rem + (x - y)
		print(int(n - sub))


for i in [0] * int(input()):
	(m, n, a) = map(int, input().split())
	x = a // m
	while True:
		if m * x + n <= a:
			print(m * x + n)
			break
		else:
			x -= 1


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	z = n // x
	m = x * z + y
	if m <= n:
		print(m)
	else:
		print(m - x)


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import OrderedDict
from collections import deque

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom

def index(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return -1

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	return -1

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return i - 1
	return -1

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return i
	return -1

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	return -1
mod = int(1000000000.0) + 7
mod2 = 998244353
t = read_int()
for i in range(t):
	(x, y, n) = read_int_line()
	if n % x >= y:
		print(n // x * x + y)
	else:
		print(n // x * x - x + y)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a >= y:
		print(n // x * x + y)
	else:
		print((n // x - 1) * x + y)


t = int(input())
while t > 0:
	t -= 1
	(x, y, n) = map(int, input().split())
	print(n - (n - y) % x)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	z = c // a * a + b
	while z > c:
		z -= a
	print(z)


t = int(input())
for w in range(t):
	(x, y, n) = (int(i) for i in input().split())
	k1 = n % x
	if y <= k1:
		print(n - (k1 - y))
	else:
		print(n - (x - y) - k1)


t = int(input())
k = t
st = list()
a = list()
while k > 0:
	s = input()
	st = s.split()
	x = int(st[0])
	y = int(st[1])
	n = int(st[2])
	w = n % x
	if w >= y:
		w = w - y
	else:
		w = w + x - y
	a.append(n - w)
	k = k - 1
for p in a:
	print(p)


import sys
from bisect import bisect_left
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()
R = lambda : map(int, input().split())
(T,) = R()
for _ in range(T):
	(x, y, n) = R()
	b = x * (n // x) + y
	if b > n:
		b -= x
	print(b)


for i in range(int(input())):
	[x, y, n] = map(int, input().split())
	a = range(0, n - y + 1, x * 10000)[-1]
	a = range(a, n - y + 1, x)[-1]
	print(a + y)


for k in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n // x
	h = 0
	for j in range(a + 1):
		if (a - j) * x + y <= n:
			print((a - j) * x + y)
			h += 1
			break
	if h == 0:
		print(0)


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def multi():
	return map(int, input().split())

def strmulti():
	return map(str, inp().split())

def lis():
	return list(map(int, inp().split()))

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def stringlis():
	return list(map(str, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for j in range(t):
	(x, y, n) = multi()
	if x > n:
		print(y)
		continue
	if n % x == y:
		print(n)
	elif y <= n % x:
		print(n - (n % x - y))
	else:
		print(n - n % x - (x - y))


from sys import stdin, stdout
INF = 100000000000.0

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()
for _ in range(int(stdin.readline())):
	(x, y, n) = get_ints()
	a = n // x
	if a * x + y > n:
		print((a - 1) * x + y)
	else:
		print(a * x + y)


t = int(input())
for i in range(t):
	arr = list(map(int, input().strip().split(' ')))
	x = arr[0]
	y = arr[1]
	n = arr[2]
	a = n - y
	b = a // x
	print(x * b + y)


n = int(input())
for i in range(n):
	(x, y, z) = [int(i) for i in input().split()]
	i = 0
	while True:
		a = z % x
		if a == y:
			print(z)
			break
		elif y < a:
			b = z - a
			c = b + y
			print(c)
			break
		else:
			b = z - a
			c = b - x
			d = c + y
			print(d)
			break


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	temp = n // x * x
	if temp + y < n:
		print(temp + y)
	elif temp + y == n:
		print(n)
	else:
		print(temp - (x - y))
	t = t - 1


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(x, y, n) = map(int, fastinput().split())
	c = n // x
	if c * x + y <= n:
		print(c * x + y)
	elif c == 0:
		print(y)
	else:
		print((c - 1) * x + y)


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	tmp = n % x
	if tmp == y:
		print(n)
	elif tmp > y:
		print(n - (tmp - y))
	elif tmp < y:
		print(n - x + (y - tmp))
	t -= 1


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	v = (n - y) // x
	print(x * v + y)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
sys.setrecursionlimit(10 ** 5)

def i():
	return sys.stdin.readline().strip()

def ii():
	return int(sys.stdin.readline())

def li():
	return list(sys.stdin.readline().strip())

def mii():
	return map(int, sys.stdin.readline().split())

def lii():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve():
	(x, y, n) = mii()
	print(n - (n - y) % x)
for _ in range(ii()):
	solve()


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 2750132
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	(x, y, n) = num_input()
	num = n // x * x
	if n - num >= y:
		print(num + y)
	else:
		print(num - x + y)
t = 1
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	g = n - n % x
	g += y
	print(g if g <= n else g - x)


t = int(input())
while t > 0:
	(x, y, n) = [int(x) for x in input().split()]
	if x * int(n / x) > n - y:
		print(x * (int(n / x) - 1) + y)
	else:
		print(x * int(n / x) + y)
	t = t - 1


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n % x
	b = n // x
	if a >= y:
		k = b * x + y
	else:
		k = (b - 1) * x + y
	print(k)


test = int(input())

def solve():
	arr = [int(i) for i in input().split()]
	x = arr[0]
	y = arr[1]
	n = arr[2]
	ans = (n - y) // x
	ans = ans * x + y
	print(ans)
while test:
	solve()
	test -= 1


t = int(input())

def maximum_k(x, y, n):
	r = n % x
	if r == y:
		return n
	elif r < y:
		return ((n - r) // x - 1) * x + y
	else:
		return n + y - r
l = []
for i in range(t):
	(x, y, n) = map(int, input().split(' '))
	l.append(maximum_k(x, y, n))
for el in l:
	print(el)


from math import *
import itertools

def r1(t):
	return t(input())

def r2(t):
	return [t(i) for i in input().split()]
for _ in range(r1(int)):
	(x, y, n) = r2(int)
	lb = 0
	ub = n + 1
	ans = 0
	while lb <= ub:
		m = (lb + ub) // 2
		if m * x + y > n:
			ub = m - 1
		else:
			ans = m
			lb = m + 1
	print(ans * x + y)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	d = n // x
	k = n % x
	if k == y:
		print(n)
	else:
		m = d * x
		if m + y <= n:
			print(m + y)
		else:
			print(m - (x - y))


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	(x, y, n) = li()
	p = n - n % x
	if p + y <= n:
		print(p + y)
	else:
		print(p - x + y)
for _ in range(I()):
	solve()


number = int(input())
for testI in range(number):
	inputs = input()
	(x, y, n) = list(map(int, inputs.split(' ')))
	modNow = n % x
	if modNow >= y:
		print(n - modNow + y)
	else:
		print(n - modNow - x + y)


a = int(input())
for item in range(a):
	(x, y, n) = input().split()
	(x, y, n) = (int(x), int(y), int(n))
	i = (n - y) // x
	print(i * x + y)


import sys

def solve(x, y, n):
	n -= y
	n //= x
	return x * n + y

def main():
	sys_in = sys.stdin
	sys_out = sys.stdout
	t = int(sys_in.readline())
	for i in range(t):
		(x, y, n) = map(int, sys_in.readline().split())
		sys_out.write(f'{solve(x, y, n)}\n')
main()


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
import math

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def divs(n, start=2):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	var = n // x
	for i in range(var, -1, -1):
		if x * i + y <= n:
			ans = x * i + y
			print(ans)
			break


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	m = n % x
	diff = y - m
	result = n + diff
	if result > n:
		result -= x
	print(result)


t = int(input())
for l in range(t):
	(x, y, n) = map(int, input().split())
	z = n % x
	if z == y:
		print(n)
	elif z > y:
		print(n - z + y)
	else:
		print(n - z - x + y)


n = int(input())
for i in range(n):
	a = [int(j) for j in input().split()]
	b = a[2] // a[0]
	if a[2] - b * a[0] < a[1]:
		print((b - 1) * a[0] + a[1])
	else:
		print(b * a[0] + a[1])


t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	var = (n - b) // a
	print(var * a + b)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	i = 0
	if n < x:
		print(y)
	else:
		r = n
		n //= x
		if n * x + y > r:
			while n * x + y > r:
				n -= 1
			print(n * x + y)
		elif n * x + y <= r:
			while n * x + y <= r:
				n += 1
			print((n - 1) * x + y)


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().strip().split()))
	ans = n // x * x + y if n // x * x + y <= n else (n - x) // x * x + y
	print(ans)


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	temp = n // x * x
	temp += y
	while temp > n:
		temp -= x
	print(temp)


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	c = n // x
	if c * x + y > n:
		print((c - 1) * x + y)
	else:
		print(c * x + y)


for tc in range(int(input())):
	(x, y, n) = map(int, input().split())
	n -= y
	print(n // x * x + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	s = n // x
	s *= x
	s += y
	if s > n:
		s -= x
	print(s)


import array
a = input()
t = int(a)
for zz in range(0, t, 1):
	aa = 0
	bb = 0
	ar = array.array('l', [])
	ar = [int(i) for i in input().split()]
	x = int(ar[0])
	y = int(ar[1])
	n = int(ar[2])
	aa = n % x
	bb = int(n / x)
	if aa == y:
		print(n)
	elif aa > y:
		print(n - (aa - y))
	elif (bb != 0) & (aa < y):
		print(n - aa - (x - y))
	else:
		print('0')


r = int(input())
for i in range(r):
	(x, y, n) = map(lambda i: int(i), input().split())
	a = n % x
	a1 = n // x
	if a < y:
		print((a1 - 1) * x + y)
	elif a == y:
		print(n)
	else:
		print(a1 * x + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	curmod = n % x
	if curmod < y:
		if n - curmod - (x - y) >= 0:
			print(n - curmod - (x - y))
		else:
			print(0)
	elif n - (curmod - y) >= 0:
		print(n - (curmod - y))
	else:
		print(0)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	if n < x:
		print(y)
		continue
	if n % x < y:
		print(n - (n % x + x) + y)
	else:
		print(n - (n % x - y))


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	m = n % x
	if m == y:
		print(n)
	elif m > y:
		temp = n - (m - y)
		print(temp)
	else:
		temp = n - m
		k = x - y
		temp = temp - k
		print(temp)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	m = n // x
	ans = x * m + y
	if ans > n:
		ans -= x
	print(ans)


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	if y == 0:
		if n < x:
			print(0)
		else:
			di = n // x
			print(di * x)
	else:
		di = n // x
		value = di * x
		if value + y <= n:
			print(value + y)
		else:
			print(value - (x - y))


from sys import stdin
from math import *
from random import randint
from collections import deque

def splt():
	return map(int, stdin.readline().split())
test = int(input())
for x in range(test):
	(a, b, n) = splt()
	w = n - b
	w = w // a
	w = w * a
	print(w + b)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	print(x * ((n - y) // x) + y)


ll = lambda : list(map(int, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
from collections import *
from math import *
for _ in range(ii()):
	(x, y, n) = v()
	w = (n - y) // x
	print(w * x + y)


for i in range(int(input())):
	(x, y, n) = [int(elem) for elem in input().split()]
	if x > n:
		print(y)
	elif n % x == y:
		print(n)
	elif n // x * x + y < n:
		print(n // x * x + y)
	else:
		print(n // x * x - x + y)


def next():
	return [int(x) for x in input().split()]
(ca,) = next()
for _ in range(ca):
	(x, y, n) = next()
	print((n - y) // x * x + y)


cases = int(input(''))
output = []
for case in range(cases):
	(x, y, n) = map(int, input().split())
	output.append(int((n - y) / x) * x + y)
print(*output, sep='\n')


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	z = n // x * x
	if z + y <= n:
		print(z + y)
	else:
		print(z - x + y)


import math
T = int(input())
for _ in range(0, T):
	(x, y, n) = map(int, input().split())
	q = (n - y) // x
	k = x * q + y
	print(k)


T = int(input())
for _ in range(T):
	(x, y, n) = map(int, input().strip().split())
	res = n - n % x + y
	if res > n:
		print(res - x)
	else:
		print(res)


test_case = int(input())
for _ in range(test_case):
	(x, y, num) = map(int, input().split())
	rem = num % x
	if rem > y:
		print(num - (rem - y))
	elif rem == y:
		print(num)
	else:
		print(num - (x - (y - rem)))


import math

def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count

def bubble_sort(c):
	n = len(c)
	for i in range(n):
		already_sorted = True
		for j in range(n - i - 1):
			if c[j][0] < c[j + 1][0]:
				(c[j][0], c[j + 1][0]) = (c[j + 1][0], c[j][0])
				already_sorted = False
			if c[j][0] == c[j + 1][0]:
				if c[j][1] > c[j + 1][1]:
					(c[j][1], c[j + 1][1]) = (c[j + 1][1], c[j][1])
		if already_sorted:
			break
	return c

def perform_bubble_sort(blist):
	(cmpcount, swapcount) = (0, 0)
	blist = list(map(int, input().split()))
	for j in range(len(blist)):
		for i in range(1, len(blist) - j):
			cmpcount += 1
			if blist[i - 1] > blist[i]:
				swapcount += 1
				(blist[i - 1], blist[i]) = (blist[i], blist[i - 1])
	print(swapcount)

def fun(l, c, d):
	if c == n:
		return d
	if c % 2 == 0:
		d = max(fun(l[:-1], c + 1, d + l[-1]), fun(l[1:], c + 1, d + l[0]))
	else:
		d = min(fun(l[1:], c + 1, d - l[0]), fun(l[:-1], c + 1, d - l[-1]))
	return d
t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		k = n % x
		a = 0
		if k < y:
			a = n - x + abs(k - y)
		else:
			a = n - abs(k - y)
		print(a)


t = int(input())
while t > 0:
	(x, y, n) = map(int, input().split())
	z = n // x
	if z * x + y <= n:
		print(z * x + y)
	else:
		z1 = z - 1
		print(z1 * x + y)
	t -= 1


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		(x, y, n) = RL()
		res = (n - y) // x * x + y
		print(res)
main()


for s in range(int(input())):
	(x, y, n) = map(int, input().split())
	print(n - (n - y) % x)


t = int(input())
s = c = 0
for i in range(t):
	(x, y, n) = map(int, input().split())
	s = (n - y) // x
	c = x * s + y
	print(c)


for i in range(int(input())):
	(x, y, n) = [int(_) for _ in input().split()]
	print(y + (n - y) // x * x)


q = int(input())
for i in range(q):
	(x, y, n) = [int(j) for j in input().split()]
	a = n % x
	if a >= y:
		print(n - (a - y))
	else:
		print(n - a - x + y)


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919]

def primef(n, plst=[]):
	if n == 1:
		return plst
	else:
		for m in primes:
			if n % m == 0:
				return primef(n // m, plst + [m])
		return primef(1, plst + [n])

def lmii():
	return list(map(int, input().split()))

def ii():
	return int(input())

def countOverlapping(string, sub):
	count = start = 0
	while True:
		start = string.find(sub, start) + 1
		if start > 0:
			count += 1
		else:
			return count
t = ii()
for i in range(t):
	(x, y, n) = lmii()
	ns = int(n)
	a = n % x
	if a == y:
		print(n)
	else:
		n //= x
		n *= x
		n += y
		if n > ns:
			n -= x
		if n < 0:
			n = 0
		print(n)


test = int(input())
for t in range(test):
	(x, y, n) = map(int, input().split())
	ans = (n - y) // x
	ans = x * ans + y
	print(ans)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	if x > n:
		print(y)
	elif x + y == n:
		print(n)
	else:
		a = n // x
		while a >= 0:
			n1 = a * x + y
			if n1 <= n:
				print(n1)
				break
			else:
				a -= 1


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	mod = y % x
	modn = n % x
	if modn == mod:
		print(n)
	else:
		if modn > mod:
			n -= modn - mod
		else:
			n -= modn + (x - mod)
		if n < 0:
			n = 0
		print(n)


t = int(input())
for i in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	c = n % x
	if c > y:
		print(n - (c - y))
	elif c < y:
		print(n - (c + x - y))
	else:
		print(n)


tests = int(input())
for _ in range(tests):
	(x, y, n) = list(map(int, input().split()))
	f = n // x * x
	if f + y <= n:
		print(f + y)
	else:
		print(f - x + y)


t = int(input())
for x in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	q = L[2] // L[0]
	r = L[2] % L[0]
	if L[1] <= r:
		k = q * L[0] + L[1]
	else:
		k = (q - 1) * L[0] + L[1]
	print(k)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	a = (n - y) // x
	print(str(a * x + y))


num_ex = input()
for i in range(int(num_ex)):
	k = 0
	string_input = input()
	list_var = string_input.split(' ')
	list_var = [int(i) for i in list_var]
	(x, y, n) = (list_var[0], list_var[1], list_var[2])
	y_temp = n % x
	if y_temp >= y:
		k = n - y_temp + y
	else:
		k = n - y_temp - (x - y)
	print(k)


t = int(input())
for i in range(0, t):
	(x, y, n) = input().split()
	a = (int(n) - int(y)) // int(x)
	k = int(int(a) * int(x) + int(y))
	print(k)


def solve():
	num_cases = int(input())
	for case in range(num_cases):
		(x, y, n) = [int(x) for x in input().split()]
		k = n - n % x + y
		if k <= n:
			print(k)
		else:
			k = n - n % x + y - x
			print(k)
	return
solve()


num_test = int(input())
for _ in range(num_test):
	(a, b, n) = map(int, input().split())
	print(a * ((n - b) // a) + b)


z = int(input())
while z > 0:
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	if n % x == y:
		k = n
	elif n % x > y:
		k = n - (n % x - y)
	else:
		k = n - n % x - (x - y)
	if k > 0:
		print(k)
	else:
		print(0)
	z = z - 1


for i in range(int(input())):
	(x, y, n) = input().split()
	a = int(x)
	b = int(y)
	c = int(n)
	z = c % a
	if z >= b:
		c -= z - b
	else:
		c += b - z
		c -= a
	print(str(c))


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	x = int(temparr[0])
	y = int(temparr[1])
	n = int(temparr[2])
	if n % x == y:
		print(n)
		continue
	quotient = n // x
	ans1 = quotient * x + y
	if ans1 <= n:
		print(ans1)
		continue
	ans2 = (quotient - 1) * x + y
	print(ans2)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	rem1 = n % x
	if rem1 >= y:
		print(n - (rem1 - y))
	else:
		temp = y - rem1
		print(n - x + temp)


t = int(input())
lst = []
while t:
	(x, y, n) = map(int, input().split())
	lst.append((n - y) // x * x + y)
	t = t - 1
for i in lst:
	print(i)


testn = int(input())
for i in range(testn):
	(x, y, n) = map(int, input().split())
	biggest_f = n // x * x
	if biggest_f + y <= n:
		print(biggest_f + y)
	else:
		print(biggest_f - x + y)


t = int(input())
while t > 0:
	(x, y, n) = [int(i) for i in input().split()]
	ost = n % x
	if ost == y:
		print(n)
	elif ost > y:
		print(n - (ost - y))
	else:
		print(n - ost - (x - y))
	t -= 1


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	(x, y, n) = [int(x) for x in input().strip().split()]
	a = n % x
	if a < y:
		print(n - x + (y - a))
	elif a > y:
		print(n - (a - y))
	else:
		print(n)


def remainder(x, y, n):
	start = n % x
	minus = start - y
	if minus < 0:
		minus = x + minus
	return n - minus
t = int(input())
for case in range(t):
	(x, y, n) = map(int, input().split())
	print(remainder(x, y, n))


for i in range(int(input())):
	inputList = input().split(' ')
	(x, y, n) = [int(num) for num in inputList]
	nmodx = n % x
	if nmodx == y:
		print(n)
	elif nmodx > y:
		print(n - (nmodx - y))
	else:
		print(n + (y - nmodx) - x)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	for i in range((n - y) // x, -1, -1):
		if (i * x + y) % x == y:
			print(i * x + y)
			break


testcases = int(input())
for i in range(testcases):
	(x, y, n) = map(int, input().split())
	initial_rem = n % x
	if initial_rem == y:
		print(n)
	elif initial_rem < y:
		print(n + (y - initial_rem) - x)
	else:
		print(n - (initial_rem - y))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = c - (c - b) % a
	print(ans)


t = int(input())
for i in range(t):
	xyn = input().split()
	x = int(xyn[0])
	y = int(xyn[1])
	n = int(xyn[2])
	print((n - y) // x * x + y)


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
res = []
for _ in range(int(input())):
	(x, y, n) = f()
	if n - n // x * x >= y:
		res.append(n // x * x + y)
	else:
		res.append((n // x - 1) * x + y)
print('\n'.join(map(str, res)))


from sys import stdin
input()
for i in stdin:
	(x, y, n) = map(int, i.split())
	if n % x >= y:
		print(n // x * x + y)
	else:
		print((n // x - 1) * x + y)


t = int(input())
for _ in range(t):
	inp = list(map(int, input().split()))
	x = inp[0]
	y = inp[1]
	n = inp[2]
	z = n % x
	if z == y:
		print(n)
		continue
	elif z > y:
		n -= z - y
		print(n)
		continue
	elif z < y:
		n += y - z - x
		print(n)


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	a = (n - y) // x
	k = x * a + y
	print(k)
	t -= 1


i = int(input())
ans = 0
z = 0
for t in range(i):
	(x, y, n) = map(int, input().split())
	z = n
	m = n % x
	if m > 0:
		z = n - m
	if z + y > n:
		z = z - x
		ans = z + y
	else:
		ans = z + y
	print(ans)


t = int(input())
while t:
	s = input().split()
	(x, y, n) = (int(s[0]), int(s[1]), int(s[2]))
	tmp = n // x * x
	if tmp + y > n:
		print(tmp + y - x)
	else:
		print(tmp + y)
	t -= 1


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	ss = n % x
	a = 0
	m = n // x * x
	if n - m >= y:
		a = m + y
	else:
		a = m - x + y
	print(a)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect

def solution():
	for i in range(int(input())):
		(x, y, n) = map(int, input().split())
		n = n - y
		n = n // x
		ans = n * x + y
		print(ans)
solution()
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def solve(x, y, n):
	main = n // x * x
	if n - main >= y:
		return main + y
	else:
		return main + y - x
counts = int(input())
for i in range(counts):
	(x, y, n) = list(map(int, input().split()))
	print(solve(x, y, n))


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	k = n // x
	ans = k * x + y
	while k > 0 and ans > n:
		k = k - 1
		ans = k * x + y
	print(ans)


t = int(input())
a = [0] * t
s = []
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	k = 0
	if n // x * x + y > n:
		k = (n // x - 1) * x + y
	else:
		k = n // x * x + y
	s.append(k)
for i in range(t):
	print(s[i])


t = input()
tt = int(t)
for i in range(tt):
	(aa, bb, cc) = input().split()
	a = int(aa)
	b = int(bb)
	c = int(cc)
	j = int(c / a)
	k = int(j * a)
	if k + b <= c:
		print(k + b)
	else:
		print((j - 1) * a + b)


t = int(input())
for k in range(t):
	(x, y, n) = map(int, input().split())
	z = n - y
	ans = z // x * x
	if ans + y > n:
		print(ans)
	else:
		print(ans + y)


import sys
tests = int(sys.stdin.readline().split()[0])
for test in range(tests):
	numbers = [int(i) for i in sys.stdin.readline().split()]
	(x, y, n) = (numbers[0], numbers[1], numbers[2])
	print((n - y) // x * x + y)


def func(x, y, n):
	temp = n // x
	result = x * temp + y
	if result <= n:
		return result
	result = x * (temp - 1) + y
	return result
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	print(func(x, y, n))


t = int(input())
for _ in range(t):
	(m, n, a) = map(int, input().split())
	h = a // m
	if h * m + n <= a and h * m + n >= 0:
		print(h * m + n)
	elif (h - 1) * m + n <= a and (h - 1) * m + n >= 0:
		print((h - 1) * m + n)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if c % a == b:
		print(c)
	elif c % a > b:
		print(c - (c % a - b))
	else:
		print(c - c % a - a + b)


T = int(input())
for _ in range(T):
	(x, y, n) = map(int, input().split())
	if n % x >= y:
		ans = n // x * x + y
	else:
		ans = (n // x - 1) * x + y
	print(ans)


t = int(input())
for i in range(t):
	res = 0
	(x, y, n) = map(int, input().split())
	if int(n - n % x + y) <= n:
		res = int(n - n % x + y)
	else:
		res = int(n - n % x - (x - y))
	print(res)


t = int(input())
for o in range(t):
	(x, y, n) = map(int, input().split())
	m = n % x
	if m == y:
		print(n)
	elif m < y:
		print(n - (m + (x - y)))
	elif m > y:
		print(n - (m - y))


def main():
	t = int(input())
	while t != 0:
		x = input()
		(x, y, n) = x.split(' ')
		x = int(x)
		y = int(y)
		n = int(n)
		k = n
		temp = k % x - y
		if temp >= 0:
			ans = k - temp
		else:
			ans = k - (temp + x)
		print(ans)
		t -= 1
main()


t = int(input())
for p in range(t):
	(x, y, n) = map(int, input().split())
	rem = n % x
	if rem == y:
		print(n)
	elif rem < y:
		pos = n - rem - (x - y)
		if pos < 0:
			pos = n + abs(rem - x)
		print(pos)
	else:
		diff = rem - y
		pos = n - diff
		if pos < 0:
			diff_2 = abs(y - rem)
			pos = n + diff_2 + y
		print(pos)


t = int(input())
while t > 0:
	t -= 1
	(x, y, n) = map(int, input().split())
	a = n // x
	b = a * x
	i = 0
	while i <= a:
		if (a - i) * x + y <= n:
			print((a - i) * x + y)
			break
		i += 1


def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = map(int, input().split())
		print((n - y) // x * x + y)
main()


t = int(input())
for i in range(t):
	inlist = list(map(int, input().split(' ')))
	(x, y, n) = (inlist[0], inlist[1], inlist[2])
	k = n - n % x + y if n - n % x + y <= n else n - n % x - (x - y)
	print(k)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	mxmult = n // x * x
	if mxmult + y <= n:
		print(mxmult + y, flush=False)
	else:
		print((n // x - 1) * x + y, flush=False)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		share = n // x
		res = (share + 1) * x
		res -= x - y
		if res > n:
			res -= x
		print(res)


def solve():
	(x, y, n) = map(int, input().split())
	temp = n
	if n % x == y:
		print(n)
	else:
		if n < x:
			print(y)
			return
		m = n % x
		n -= m
		if n == 0:
			print(0)
		elif n % x == y:
			print(n)
		else:
			rem = x - y
			new1 = n - rem
			new2 = n + y
			if new2 <= temp:
				print(new2)
			else:
				print(new1)
for _ in range(int(input())):
	solve()


n = int(input())
for i in range(n):
	seq = input()
	A = seq.split()
	x = int(A[0])
	y = int(A[1])
	n = int(A[2])
	if n % x < y:
		print(n - n % x - x + y)
	else:
		print(n - (n % x - y))


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x < y:
		print(n - n % x - x + y)
	else:
		print(n - n % x + y)


for k in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x >= y:
		print(n - (n % x - y))
	else:
		print(n - x + y - (n - x) % x)


for tt in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = 0
	if n % x > y:
		ans = n - (n % x - y)
	if n % x == y:
		ans = n
	if n % x < y:
		ans = n + (y - n % x) - x
	print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	print((n - y) // x * x + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	nn = n // x
	p = nn * x + y
	if p > n:
		p = p - x
	print(p)


import math
from decimal import *
getcontext().prec = 30
t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	rem = n % x
	last = n - rem
	possible = last + y
	if possible > n:
		print(possible - x)
	else:
		print(possible)


for _ in range(int(input())):
	(x, y, n) = map(int, input().rstrip().split())
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		print(n - (r - y))
	else:
		print(n - r - x + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	rem = n % x
	if rem >= y:
		print(n - rem + y)
	elif rem < y:
		print(n - rem - x + y)


def solve():
	(x, y, n) = map(int, input().split())
	k = n - n % x + y
	if k > n:
		k = k - x
	print(k)
t = int(input())
for h in range(t):
	solve()


t = int(input())
for i in range(t):
	a = input().split()
	x = int(a[0])
	y = int(a[1])
	n = int(a[2])
	q = n % x
	if q >= y:
		print(n - (q - y))
	else:
		print(n - (q + (x - y)))


t = int(input())
while t > 0:
	(x, y, n) = map(int, input().strip().split())
	current_remainder = n % x
	required_remainder = y
	if current_remainder == required_remainder:
		print(n)
	elif required_remainder < current_remainder:
		val_to_subtract_from_n = current_remainder - required_remainder
		print(n - val_to_subtract_from_n)
	else:
		dist = required_remainder - current_remainder
		total_distance = x - 1
		val_to_subtract_from_n = total_distance - dist + 1
		print(n - val_to_subtract_from_n)
	t -= 1


import math
for _ in range(int(input())):
	(x, y, n) = map(int, input('').split())
	temp = n % x
	if temp == y:
		ans = n
	if temp < y:
		ans = n - x + (y - temp)
	else:
		ans = n - (temp - y)
	print(ans)


T = int(input().rstrip())
for tt in range(T):
	(x, y, n) = list(map(int, input().rstrip().split(' ')))
	val = n % x
	val2 = n - val + y if n - val + y <= n else n - val - (x - y)
	print(val2)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	rem = n % x
	if rem > y:
		ans = n - (rem - y)
	elif rem < y:
		ans = n - rem - (x - y)
	else:
		ans = n
	print(ans)


n = int(input())
for i in range(n):
	(a, b, c) = [int(i) for i in input().split(' ')]
	print(a * ((c - b) // a) + b)


t = int(input())
while t:
	(x, y, n) = map(int, input().split(' '))
	a = n % x
	if a >= y:
		n = n - a + y
	else:
		n = n - a - x + y
	print(n)
	t = t - 1


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if x > n:
		print(y)
		continue
	else:
		c = n // x
		while c >= 0:
			if c * x + y <= n:
				print(c * x + y)
				break
			c -= 1


for t in range(int(input())):
	(x, y, k) = map(int, input().split())
	r = k % x
	if r == y:
		print(k)
	elif r > y:
		print(k - (r - y))
	else:
		print(k - x + (y - r))


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	cur = x
	(l, r) = (0, n + 1)
	while l < r - 1:
		mid = (l + r) // 2
		if mid * cur + y > n:
			r = mid
		else:
			l = mid
	print(l * cur + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	q = n // x
	ans = q * x + y
	if ans <= n:
		print(ans)
	else:
		print(ans - x)


for _ in range(int(input())):
	a = [int(_) for _ in input().split()]
	currMod = a[2] % a[0]
	if currMod == a[1]:
		print(a[2])
	elif currMod > a[1]:
		print(a[2] - (currMod - a[1]))
	else:
		print(a[2] - currMod - (a[0] - a[1]))


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	n1 = int(n / a) - 1
	if int(n / a) * a + b <= n:
		print(int(n / a) * a + b)
	else:
		print(a * n1 + b)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	elif y == 0 and x > n:
		print(0)
	else:
		z = abs(y - n % x)
		if (n - z) % x == y:
			print(n - z)
		else:
			print(n - (x - z))


for r in [*open(0)][1:]:
	(x, y, k) = map(int, r.split())
	print(k - (k - y) % x)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if y == 0 and n < x:
		print(0)
	else:
		modval = n % x
		if modval >= y:
			temp = modval - y
			temp1 = n - temp
			print(temp1)
		else:
			temp = abs(x - y)
			total = temp + modval
			result = n - total
			print(result)


a = int(input())
i = 0
while i < a:
	b = input().split(' ')
	x = int(b[0])
	y = int(b[1])
	n = int(b[2])
	z = n - y
	print(z - z % x + y)
	i = i + 1


from sys import stdin, stdout
from types import FunctionType
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	for i in range(n // x, -1, -1):
		k = x * i + y
		if -1 < k <= n:
			print(k)
			break


for u in range(int(input())):
	(x, y, n) = map(int, input().split())
	r = n % x
	if r == y:
		print(n)
	else:
		if r < y:
			s = n // x * x
			s = s - (x - y)
		else:
			s = n // x * x
			s = s + y
		print(s)


n = int(input())
for i in range(n):
	(x, y, z) = map(int, input().split())
	p = z
	re = z % x
	z = z - re
	if z + y <= p:
		print(z + y)
	else:
		print(z - (x - y))


for test in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n // x
	if a * x + y > n:
		a -= 1
	print(a * x + y)


t = int(input())
while t != 0:
	(x, y, n) = list(map(int, input().split()))
	k = n
	while k % x != y:
		m = k % x
		if m < y:
			k = k - x
			k = k + (y - m)
		elif m > y:
			k = k - (m - y)
	print(k)
	t = t - 1


import math
t = int(input())
list = []
for u in range(1, t + 1):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	c = x * math.floor(n / x) + y
	if c <= n:
		list.append(c)
	else:
		list.append(c - x)
for x in list:
	print(x)


from math import *

def _in():
	return [int(x) for x in input().split(' ')]
tt = int(input())
for _ in range(tt):
	(x, y, n) = _in()
	ma = n // x * x
	ans = ma + y
	if ans <= n:
		print(ans)
	else:
		print(ans - x)


T = int(input())
while T:
	T -= 1
	(x, y, n) = map(int, input().split())
	temp = n % x
	if temp == y:
		print(n)
		continue
	elif temp < y:
		diff = x - abs(y - temp)
		print(n - diff)
	else:
		print(n - abs(temp - y))


from sys import stdin
t = int(input())
while t:
	t += -1
	(x, y, n) = map(int, input().split())
	tmp = x * (n // x)
	ans = -1
	if tmp + y <= n:
		ans = tmp + y
	else:
		ans = tmp - (x - y)
	print(ans)


for _ in range(int(input())):
	(x, y, k) = map(int, input().split())
	if y == 0 and k < x:
		print(0)
	elif k % x == y:
		print(k)
	elif k % x < y:
		print(x * (k // x - 1) + y)
	else:
		print(k - k % x + y)


t = int(input())
for test in range(t):
	(x, y, n) = map(int, input().split())
	c = n % x
	if y <= c:
		result = n - (c - y)
	else:
		result = n - c - (x - y)
	print(result)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	r = n % x
	y = y % x
	if n - r + y > n:
		l = n - r + y - x
		print(l)
	else:
		print(n - r + y)


for i in range(int(input())):
	a = list(map(int, input().split()))
	x = a[0]
	y = a[1]
	n = a[2]
	b = n % x
	if b > y:
		print(n - (b - y))
	elif b < y:
		print(n - (x + b - y))
	elif b == y:
		print(n)
	else:
		print(0)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	lowlimit = n // x
	low = lowlimit * x
	if low + y > n:
		print(low + (y - x))
	else:
		print(low + y)


t = int(input())
for test in range(t):
	(x, y, n) = map(int, input().split())
	curr = n % x
	diff = curr - y
	diff = diff if diff >= 0 else diff + x
	res = n - diff
	print(res)


for testcase in range(int(input())):
	(x, y, n) = map(int, input().split())
	initial = n % x
	if initial == y:
		print(n)
	elif initial > y:
		print(n - (initial - y))
	elif initial < y:
		print(n - (initial + (x - y)))


t = int(input())
arr = []
while t > 0:
	lst = input().split(' ')
	for i in range(len(lst)):
		lst[i] = int(lst[i])
	(x, y, n) = (lst[0], lst[1], lst[2])
	mod = n % x
	if mod == y:
		arr.append(n)
	elif mod < y:
		mod = y - mod
		n -= x
		n += mod
		arr.append(n)
	else:
		mod = mod - y
		n -= mod
		arr.append(n)
	t -= 1
for i in arr:
	print(i)


def solve():
	(x, y, n) = map(int, input().split())
	k = n % x
	if k >= y:
		print(n - k + y)
	else:
		print(n - x - k + y)
[solve() for i in range(int(input()))]


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	a = y % x
	b = n % x
	if b >= a:
		print(n - (b - a))
	else:
		p = n // x
		print((p - 1) * x + a)


for _ in range(int(input())):
	(x, y, n) = [int(c) for c in input().split()]
	ans = (n - y) // x
	print(ans * x + y)


test = int(input())
for _ in range(test):
	(x, y, n) = map(int, input().split())
	a = n // x
	v = x * a + y
	if v > n:
		v -= x
	print(v)


import time
from collections import deque

def inpt():
	return int(input())

def inpl():
	return list(map(int, input().split()))

def inpm():
	return map(int, input().split())

def solve():
	(x, y, n) = inpm()
	if n % x == y:
		print(n)
		return
	elif n % x > y:
		print(n - n % x + y)
	else:
		print(x * (n // x - 1) + y)

def main():
	m = 10 ** 9 + 7
	t = int(input())
	while t:
		t -= 1
		solve()
main()


import sys
import math
input = lambda : sys.stdin.readline().rstrip()

def solve(x, y, n):
	first_mod = n % x
	temp = n - n % x
	if y > first_mod:
		temp -= x - y
	else:
		temp += y
	return temp

def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = [int(v) for v in input().split()]
		print(solve(x, y, n))
main()


def solve1():
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	elif n % x > y:
		print(n - (n % x - y))
	else:
		print(n - n % x - (x - y))
for _ in range(int(input())):
	solve1()


t = int(input())
for i in range(t):
	tit = str(input()).split()
	x = int(tit[0])
	y = int(tit[1])
	n = int(tit[2])
	k = n // x * x + y
	if k > n:
		k -= x
	print(k)


import sys
data = sys.stdin.readlines()
for i in range(int(data[0])):
	a = list(map(int, data[i + 1].split(' ')))
	x = a[0]
	y = a[1]
	n = a[2]
	if n % x == y:
		print(n)
	elif n % x > y:
		print(n - n % x + y)
	else:
		print(n - n % x + y - x)


while True:
	try:
		t = eval(input())
		for i in range(t):
			(x, y, n) = map(int, input().split())
			print((n - y) // x * x + y)
	except:
		break


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	elif n % x > y:
		b = n % x - y
		print(n - b)
	else:
		diff = n - n % x
		b = diff - (x - y)
		print(b)


p = int(input())
for i in range(p):
	(x, y, n) = map(int, input().split())
	k = n // x * x + y
	if k > n:
		k -= x
	print(k)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n - n // x * x == y:
		print(n)
	elif n // x * x + y <= n:
		print(n // x * x + y)
	else:
		v = (n // x - 1) * x
		print(v + y)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
t = fi()
while t > 0:
	t -= 1
	(x, y, n) = mi()
	l = 0
	r = 10 ** 9 + 1
	ans = y
	while l <= r:
		mid = (l + r) // 2
		if mid * x + y <= n:
			ans = mid * x + y
			l = mid + 1
		else:
			r = mid - 1
	print(ans)


from sys import stdin, stdout
from bisect import bisect, bisect_left, bisect_right

def gt():
	return map(int, stdin.readline().split())

def gi():
	return int(stdin.readline())

def gl():
	return list(map(int, stdin.readline().split()))

def gs():
	return stdin.readline()
t = gi()
for _ in range(t):
	(x, y, n) = gt()
	temp = n // x
	if y == 0:
		print(temp * x)
		continue
	if n % x == 0:
		temp = n // x - 1
	if temp * x + y <= n:
		print(temp * x + y)
	else:
		print((temp - 1) * x + y)


t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	loda = n % x
	if loda == y:
		print(n)
	else:
		gand = n - loda + y
		if gand <= n:
			print(n - loda + y)
		else:
			print(n - loda - x + y)


test = int(input())
for t in range(test):
	(x, y, n) = map(int, input().split())
	a = n - y
	b = a // x
	k = b * x + y
	print(k)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	mod = c % a
	m = c - mod
	while m + b > c:
		m -= a
	print(m + b)


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	fy = n % x
	if fy == y:
		print(n)
	elif fy > y:
		d = fy - y
		print(n - d)
	else:
		gi = n - fy - x
		print(gi + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	m = (n - y) // x
	ans = y + m * x
	print(ans)


t = int(input())
for T in range(t):
	(x, y, n) = map(int, input().split())
	a = (n - y) % x
	print(n - a)


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	temp = n % x
	k = temp - y
	if k >= 0:
		res = n - k
	else:
		res = n - k - x
	print(res)


def solve(x, y, n):
	f = n // x * x
	k = f + y
	if k <= n:
		return k
	return k - x
t = int(input())
answers = []
while t:
	t -= 1
	(x, y, n) = tuple(map(int, input().split()))
	answers.append(solve(x, y, n))
print(*answers, sep='\n')


for iii in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	tmp = n % x
	if tmp >= y:
		print(n - abs(y - tmp))
	else:
		z = n // x
		while z * x + y > n:
			z -= 1
		print(z * x + y)


t = int(input())
for caso in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	res = -1
	if n % x < y:
		n = n - n % x - 1
	if n % x >= y:
		res = n - (n % x - y)
	print(res)


t = int(input())
while t != 0:
	t = t - 1
	inputm = input()
	list = []
	list = inputm.split(' ')
	x = int(list[0])
	y = int(list[1])
	n = int(list[2])
	a = n % x
	b = a - y
	final = n - b
	if final > n:
		final = final - x
	print(final)


t = int(input())
while t:
	t = t - 1
	(x, y, n) = map(int, input().split())
	k = n // x
	kk = k * x + y
	if kk > n:
		print(kk - x)
	else:
		print(kk)


t = int(input())
ans = [0] * t
for i in range(t):
	(x, y, n) = map(int, input().split())
	ans[i] = n - (n % x - y) % x
for i in ans:
	print(i)


for _ in range(int(input())):
	(x, y, n) = [int(c) for c in input().split()]
	m = n // x
	while m * x + y > n:
		m -= 1
	print(m * x + y)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	theta = (n - y) // x
	k = theta * x + y
	print(k)


t = int(input())
import math
M = []

def fonction(x, y, n):
	return (n - y) // x * x + y
for i in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	M.append(fonction(x, y, n))
for k in M:
	print(k)


T = int(input())
for i in range(T):
	(x, y, n) = [int(e) for e in input().split(' ')]
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


tq = int(input())
for _ in range(tq):
	(x, y, n) = map(int, input().split())
	d = n % x
	if d == y:
		print(n)
		continue
	if d == 0:
		d = x
	if d < y:
		n -= d
		d = x
	print(n - d + y)


t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	l = n - b
	p = l // a
	print(a * p + b)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = 0
	if n % x == y:
		ans = n
	elif n % x < y:
		ans = max(n - n % x - (x - y), ans)
	elif n % x > y:
		ans = max(n - (n % x - y), ans)
	print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	r1 = n // x
	r2 = n % x
	res = x * r1 + y
	if res > n:
		res = x * (r1 - 1) + y
	print(res)


n = int(input())
for i in range(n):
	(x, y, k_max) = map(int, input().split())
	r = int((k_max - y) / x)
	print(r * x + y)


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(x, y, n):
	if n % x == y:
		return n
	mod = n % x
	if mod > y:
		return n - (mod - y)
	k = n - y
	mod = k % x
	return k - (mod - y)
t = read_int()
for case in range(t):
	(x, y, n) = read_ints()
	sol = solve(x, y, n)
	print(sol)


t = int(input())
for test in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	if n // x * x + y > n:
		print((n // x - 1) * x + y)
	else:
		print(n // x * x + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	temp = n // x
	k = temp * x + y
	if k <= n:
		print(k)
	else:
		temp -= 1
		print(temp * x + y)


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	(x, y, n) = (a[0], a[1], a[2])
	ans = n // x * x + y
	if ans <= n:
		print(ans)
	else:
		for i in range(ans - x, -1, -1):
			if i % x == y:
				print(i)
				break


from math import floor
l = []
for _ in range(int(input())):
	numbers = input().split()
	(x, y, n) = (int(numbers[0]), int(numbers[1]), int(numbers[2]))
	k = floor(n / x) * x
	if k + y <= n:
		l.append(str(k + y))
	else:
		l.append(str(k - x + y))
print('\n'.join(l))


from math import *
from collections import *
from bisect import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	re = n % x
	k = n // x
	if n % x < y:
		k -= 1
	r = k * x + y
	print(r)


t = int(input())
for p in range(t):
	(x, y, n) = map(int, input().split())
	c = n // x
	ans = x * c + y
	if ans > n:
		ans -= x
	print(ans)


def get_arry():
	return list(map(int, input().split()))

def get_int():
	return int(input())

def get_input():
	return input()

def main():
	for _ in range(int(input())):
		n = get_arry()
		(x, y, m) = (n[0], n[1], n[2])
		ans = m // x * x + y
		while ans > n[2]:
			m -= x
			ans = m // x * x + y
		print(ans)
main()


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(x, y, n) = map(int, stdin.readline().split())
	t = n % x
	if t < y:
		stdout.write(str(n - t - x + y) + '\n')
	elif t > y:
		stdout.write(str(n - t + y) + '\n')
	else:
		stdout.write(str(n) + '\n')


t = int(input())
ans = []
for i in range(t):
	(x, y, n) = input().split()
	(x, y, n) = (int(x), int(y), int(n))
	ini = n % x
	if ini >= y:
		ans.append(n - (ini - y))
		continue
	else:
		te = n - x + (y - ini)
		ans.append(te)
		continue
for an in ans:
	print(an)


t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	ans = n - (n % x + (x - y)) % x
	print(ans)


T = int(input())
for i in range(T):
	(x, y, n) = map(int, input().split())
	remain = n % x
	diff = remain - y
	K = 0
	if diff == 0:
		K = n
	elif diff < 0:
		n = n - remain
		n = n - (x - y)
		K = n
	else:
		K = n - diff
	print(K)


t = int(input())
for j in range(t):
	g = input().split()
	x = int(g[0])
	y = int(g[1])
	n = int(g[2])
	ans = n - n % x + y
	if ans > n:
		ans -= x
	print(ans)


TC = int(input())
for tc in range(TC):
	(X, Y, N) = map(int, input().split())
	result = (N - Y) // X
	print(result * X + Y)


def solve():
	(x, y, n) = list(map(int, input().split()))
	if n % x < y:
		n = n - n % x - 1
	tosub = abs(y - n % x)
	print(n - tosub)
t = 1
t = int(input())
for _ in range(t):
	solve()


n = int(input())
for i in range(n):
	(a, b, c) = [int(x) for x in input().split()]
	i = c % a
	j = a - b
	if c % a == b:
		print(c)
	elif b == 0:
		print(c - i)
	elif i < b:
		print(c - i - j)
	elif i > b:
		print(c - i + b)


def main():
	t = int(input())
	for case in range(t):
		(x, y, n) = input().split()
		x = int(x)
		y = int(y)
		n = int(n)
		rem = n % x
		if rem == y:
			print(n)
		elif rem < y:
			print(n - rem - (x - y))
		else:
			print(n - (rem - y))
main()


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	(x, y, n) = read()
	if y == 0:
		print(n // x * x)
		return
	val = n // x * x
	if val + y <= n:
		print(val + y)
	else:
		print(val - (x - y))
for _ in range(int(input())):
	solve()


def restoExigido(divisor, resto, limite):
	auxiliar = limite % divisor
	if auxiliar == resto:
		return limite
	elif auxiliar < resto:
		maiorDividendo = limite + (resto - auxiliar) - divisor
	else:
		maiorDividendo = limite - (auxiliar - resto)
	return maiorDividendo
t = int(input())
contador = 0
while contador < t:
	(x, y, n) = map(int, input().split())
	resultado = restoExigido(x, y, n)
	print(resultado)
	contador += 1


for i in ' ' * int(input()):
	(x, y, n) = map(int, input().split())
	z = n // x * x + y
	if z > n:
		z -= x
	print(z)


def main(n, x, y):
	if n % x == y:
		return n
	else:
		rem = n % x
		if rem > y:
			return n - (rem - y)
		else:
			dis = rem + (x - y)
			if n - dis >= 0:
				return n - dis
			else:
				return y
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	ans = main(n, x, y)
	print(ans)


ans = ''
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	k = n % x
	if k < y:
		m = n - x + (y - k)
	elif k > y:
		m = n - (k - y)
	else:
		m = n
	ans += str(m) + '\n'
print(ans)


def solution(x, y, n):
	val = n % x
	if val == y:
		return n
	if val > y:
		return n - (val - y)
	if val < y:
		return n - x + (y - val)
for _ in range(int(input())):
	(x, y, k) = map(int, input().split())
	ans = solution(x, y, k)
	print(ans)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(x, y, n) = value()
	large = n // x
	if n % x >= y:
		print(large * x + y)
	else:
		large -= 1
		print(large * x + y)


cases = []
for i in range(int(input())):
	cases.append(list(map(int, input().strip().split())))

def solve(case):
	(x, y, n) = case
	m = n // x
	r = m * x + y
	if r > n:
		r -= x
	print(r)
for case in cases:
	solve(case)


import sys
import math
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	(x, y, n) = list(map(int, input().split(' ')))
	z = (n - y) / x
	z = math.floor(z)
	print(z * x + y)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		p = n // x
		q = p * x + y
		if q <= n:
			print(q)
		else:
			q -= x
			print(q)


for _ in range(int(input())):
	arr = [int(i) for i in input().split()]
	if arr[2] % arr[0] < arr[1]:
		print(arr[2] - arr[2] % arr[0] - (arr[0] - arr[1]))
	elif arr[2] % arr[0] > arr[1]:
		print(arr[2] - (arr[2] % arr[0] - arr[1]))
	else:
		print(arr[2])


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
test = int(input())
while test != 0:
	(x, y, n) = [int(x) for x in input().split()]
	ans = n // x
	res = ans * x + y
	while res > n:
		res -= x
	print(res)
	test -= 1


for ct in range(int(input())):
	(x, y, n) = map(int, input().split())
	k = n - n % x + y
	k -= (k > n) * x
	print(k)


T = int(input())
for t in range(T):
	(x, y, n) = list(map(int, input().split()))
	if n % x == y:
		print(n)
		continue
	i = n
	while i >= 0:
		rem = i % x
		if rem == y:
			print(i)
			break
		elif rem > y:
			i -= rem - y
		elif rem == 0:
			i -= 1
		else:
			i -= rem


t = int(input())
for i in range(t):
	k = []
	(x, y, n) = map(int, input().split())
	if n >= n - n % x + y:
		k.append(n - n % x + y)
	else:
		k.append(n - n % x - (x - y))
	print(max(k))


t = int(input())
for i in range(t):
	k = list(map(int, input().split()))
	v = k[2] // k[0]
	m = k[2] % k[0]
	if m >= k[1]:
		print(v * k[0] + k[1])
	else:
		print((v - 1) * k[0] + k[1])


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def main(x, y, n):
	res = n // x * x + y
	if res > n:
		res = n // x * x - (x - y)
	print(res)
N = int(input())
for i in range(N):
	(x, y, n) = get_ints()
	main(x, y, n)


x = int(input())
for i in range(x):
	(a, b, c) = [int(x) for x in input().split()]
	if a > c:
		print(b)
	else:
		c -= a
		if b > c % a:
			c += b - c % a
		else:
			c += b + a - c % a
		print(c)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().strip().split())
	f = n % x
	ghat = n - f
	if ghat + y > n:
		while ghat + y > n:
			ghat -= x
	print(ghat + y)


t = int(input())
for _ in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	c = n // x
	if c * x + y <= n:
		print(c * x + y)
	else:
		i = 1
		while (c - i) * x + y > n:
			i += 1
		print((c - i) * x + y)


k = int(input())
res = [0] * k
for i in range(k):
	(x, y, n) = map(int, input().split())
	z = (n - y) // x
	res[i] = z * x + y
for i in res:
	print(i, end='\n')


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	(x, y, n) = rm()
	print((n - y) // x * x + y)


test_cases = int(input())
for i in range(test_cases):
	(div, rem, limit) = map(int, input().split())
	mod = limit % div
	if mod == rem:
		print(limit)
	elif mod <= rem:
		print(limit - mod - (div - rem))
	else:
		print(limit - (mod - rem))


def greatest_int(x, y, n):
	m = n % x
	if m == y:
		return n
	if n - m + y <= n:
		return n - m + y
	elif n - m - x + y <= n:
		return n - m - x + y
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	print(greatest_int(x, y, n))


T = int(input())
for t in range(T):
	(x, y, n) = map(int, input().split())
	d = n // x
	while True:
		k = d * x + y
		if k <= n:
			print(k)
			break
		d = d - 1


t = int(input())
for _ in range(t):
	(x, y, n) = tuple(map(int, input().split()))
	if n % x >= y:
		result = n // x * x + y
	else:
		result = n // x * x + (y - x)
	print(result)


t = int(input())
for i in range(t):
	line = input().strip().split(' ')
	(x, y, n) = (int(line[0]), int(line[1]), int(line[2]))
	ans = n // x * x + y
	while ans > n:
		ans -= x
	print(ans)


import math

def shrey():
	(x, y, n) = map(int, input().split())
	ans = (n - y) // x * x + y
	print(ans)
T = input()
T = int(T)
for q in range(1, T + 1):
	shrey()


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	if n == x:
		if y == 0:
			print(x)
		else:
			print(y)
		continue
	if n < x:
		print(y)
	else:
		res = n // x * x + y
		if res > n:
			res -= x
		print(res)


t = int(input())
for qw in range(t):
	(x, y, n) = map(int, input().split())
	p = (n - y) // x
	k = p * x + y
	print(k)


vals = int(input())
while vals > 0:
	(x, y, n) = list(map(int, input().split()))
	bob = n % x
	if bob < y:
		ans = n - bob - (x - y)
	else:
		ans = n - (bob - y)
	if ans <= 0:
		print('0')
	else:
		print(ans)
	vals -= 1


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	m = (n - y) // x
	k = m * x + y
	print(k)


def nod(a, b):
	while a != b:
		(a, b) = (max(a, b), min(a, b))
		if a % b == 0:
			a -= (a // b - 1) * b
		else:
			a -= a // b * b
	return a
for t in range(int(input())):
	(x, y, n) = [int(x) for x in input().split()]
	print(y + x * ((n - y) // x))


def solve():
	(x, y, z) = map(int, input().split(' '))
	a = z % x
	if a - y >= 0:
		z = z - (a - y)
	else:
		z = z - a - x + y
	print(z)
n = int(input())
for i in range(n):
	solve()


cases = int(input())
for v in range(cases):
	a = list(map(int, input().strip().split()))
	x = a[0]
	y = a[1]
	n = a[2]
	rem = n % x
	if rem == y:
		print(n)
	elif rem > y:
		print(n - (rem - y))
	else:
		n = n - rem
		n = n - (x - y)
		print(n)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a == y:
		a = n
		while a >= 0:
			if a % x == y:
				print(a)
				break
			a -= 1
	else:
		a = y - a
		a = n + a
		if a % x == y and a <= n:
			print(a)
		else:
			print(a - x)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	m = n % x
	if m == y:
		print(n)
	else:
		d = n - m + y
		if d > n:
			d -= x
		print(d)


noOfTests = int(input())
outputs = []
for i in range(noOfTests):
	thisLine = [int(x) for x in input().split(' ')]
	divisor = thisLine[0]
	remainder = thisLine[1]
	maxnum = thisLine[2]
	test1 = maxnum % divisor
	if test1 == remainder:
		outputs.append(maxnum)
	elif test1 > remainder:
		difference = test1 - remainder
		outputs.append(maxnum - difference)
	else:
		difference = test1 - remainder + divisor
		outputs.append(maxnum - difference)
print('\n'.join((str(x) for x in outputs)))


test_cases = int(input())
for e in range(test_cases):
	lista = list(map(int, input().split()))
	(x, y, n) = lista
	ans = 0
	ans = n - n % x + y
	if n > ans:
		print(ans)
	else:
		ans -= (ans > n) * x
		print(ans)


N = int(input())
i = 0
while i < N:
	l = list(map(int, input().split()))
	mod = l[2] % l[0]
	if mod >= l[1]:
		print(l[2] - mod + l[1])
	else:
		print(l[2] - mod + l[1] - l[0])
	i += 1


import getopt
import sys
import math
onlyCase = -1
verbose = False
try:
	(opts, args) = getopt.getopt(sys.argv[1:], 'vc:', ['case='])
except getopt.GetoptError as err:
	print(str(err))
	sys.exit(2)
for (o, a) in opts:
	if o in ('-c', '--case'):
		onlyCase = int(a)
	elif o == '-v':
		verbose = True
	else:
		sys.exit()
ncases = int(input())
for c in range(1, ncases + 1):
	(x, y, n) = [int(x) for x in input().split()]
	if onlyCase != -1 and onlyCase != c:
		continue
	if verbose:
		print('[%d mod %d == %d]' % (n, x, y))
		print('n//x == %d -> %d' % (n // x, n // x * x))
	s = n // x * x + y
	while s > n:
		s -= x
	print('%d' % s)


def ans():
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	a = n % x
	if a == y:
		print(n)
	elif a > y:
		print(n - (a - y))
	else:
		print(n - a - (x - y))
t = int(input())
for i in range(t):
	ans()


t = int(input())
for _ in range(t):
	(x, y, n) = tuple(map(int, input().split()))
	m = n % x
	if m > y:
		n = n - m + y
	elif m < y:
		n = n - x + y - m
	print(n)


a = input()
for i in range(int(a)):
	ans = 0
	s = input()
	l = s.split(' ')
	a = int(l[0])
	b = int(l[1])
	c = int(l[2])
	j = c
	while j <= c and j >= 0:
		if j % a == b:
			ans = j
			break
		else:
			r = j % a - b
			if r < 0:
				j = j - a - r
			else:
				j = j - r
	print(ans)


n = int(input())
for i in range(n):
	(x, y, n) = map(int, input().split())
	d = n // x
	k = d * x + y
	while k > n:
		d = d - 1
		k = d * x + y
	print(k)


t = int(input())
for z in range(t):
	(x, y, n) = [int(q) for q in input().split()]
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		print(n - (r - y))
	else:
		print(n - x + (y - r))


from math import floor

def find_req_rem(x, y, n):
	max_factor = floor(n / x)
	while max_factor * x + y > n:
		max_factor -= 1
	return max_factor * x + y
t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	no_of_ops = find_req_rem(a, b, n)
	print(no_of_ops)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	q = n // x
	r = n % x
	if r >= y:
		a = x * q + y
	else:
		a = x * (q - 1) + y
	if a == 0:
		print(0)
	else:
		print(a)


for s in [*open(0)][1:]:
	(y, l, n) = map(int, s.split())
	Z = n - (n - l) % y
	print(Z)


for p in range(int(input())):
	(x, y, n) = map(int, input().split())
	d = abs(n - (n % x - y))
	if d <= n:
		print(d)
	else:
		print(n - (n - y) % x)


t = int(input())
i = 0
while i < t:
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	a = n % x
	if a > y:
		k = n - (a - y)
	elif a < y:
		k = n - (a + (x - y))
	elif a == y:
		k = n
	print(k)
	i += 1


def solve():
	(x, y, n) = map(int, input().split())
	if n % x >= y:
		print(n - (n % x - y))
	else:
		print(n - (n % x - y) - x)
t = int(input())
while t > 0:
	solve()
	t -= 1


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	m = n % x
	if y == m:
		print(n)
	elif y == 0:
		print(n - m)
	elif y > m:
		print(n - m - (x - y))
	else:
		print(n - (m - y))


x = int(input())
while x:
	(a, b, c) = map(int, input().split())
	d = c // a
	while d >= 0:
		if d * a + b <= c:
			print(d * a + b)
			break
		else:
			d -= 1
	x -= 1


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	i = n % x
	j = n // x
	if i < y:
		print(x * (j - 1) + y)
	else:
		print(n - (i - y))


t = int(input())
for i in range(0, t):
	(x, y, n) = list(map(int, input().split()))
	if n % x != y:
		r = n % x
		if r > y:
			n = n - (r - y)
			print(n)
		else:
			n = n - (r + x - y)
			print(n)
	else:
		print(n)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split(' '))
	k = n % x
	if k >= y:
		print(str(n - (k - y)))
	else:
		print(str(n - (k - y + x)))


t = int(input())
for i in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	if n % x < y:
		n -= n % x + 1
	k = n // x * x + y
	print(k)


import math
t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	print(math.floor((n - y) / x) * x + y)


import string
import math
n = int(input())
while n > 0:
	arr = list(map(int, input().strip().split()))
	x = arr[0]
	y = arr[1]
	z = arr[2]
	ct = 0
	a = int(z / x)
	temp = a * x + y
	if temp <= z:
		ct = temp
	else:
		temp = (a - 1) * x + y
		ct = temp
	print(temp)
	n = n - 1


def Required_Remainder(x, y, n):
	if x * (n // x) + y <= n:
		return x * (n // x) + y
	else:
		return x * (n // x - 1) + y
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	print(Required_Remainder(x, y, n))


t = int(input())
while t > 0:
	l = list(map(int, input().split()))
	t1 = l[2] // l[0]
	if t1 * l[0] + l[1] > l[2]:
		print((t1 - 1) * l[0] + l[1])
	else:
		print(t1 * l[0] + l[1])
	t -= 1


t = int(input())
for u in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	if n % x == y:
		print(n)
	elif n % x < y:
		t = n % x
		print(n - t - x + y)
	elif n % x > y:
		t = n % x
		print(n - t + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	d = n // x
	if d * x + y > n:
		d -= 1
		print(d * x + y)
	else:
		print(d * x + y)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	while True:
		if n % x == y:
			print(n)
			break
		elif n % x == n:
			print(y)
			break
		elif n % x < y:
			n -= n % x + (x - y)
		else:
			n -= n % x - y


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	m = int(n / x)
	if m * x + y > n:
		m = m - 1
		print(m * x + y)
	else:
		print(m * x + y)


import math as m
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	d = m.floor(n // x)
	req = x * d + y
	if req % x == y:
		if req > n:
			print(x * (d - 1) + y)
		else:
			print(req)


for i in range(int(input())):
	xyn = list(map(int, input().split(' ')))
	(x, y, n) = (xyn[0], xyn[1], xyn[2])
	M = (n - y) // x
	print(x * M + y)


from sys import stdin

def input():
	return stdin.readline()
T = int(input())
for _ in range(T):
	(x, y, n) = map(int, input().split())
	ost = n - n // x * x
	if ost >= y:
		print(n - (ost - y))
	else:
		print(n - (ost + x - y))


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	u = n % x
	v = u - y
	if v < 0:
		v = v + x
	print(n - v)


from sys import stdin
N = int(stdin.readline())
for case in range(N):
	(x, y, n) = map(int, stdin.readline().split())
	remainder = n % x
	if remainder >= y:
		print(n - remainder + y)
	else:
		print(n - remainder - (x - y))


t = int(input())
for tt in range(0, t, 1):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	if y == n % x:
		print(n)
	elif y > n % x:
		print(n - x + (y - n % x))
	elif y < n % x:
		print(n - n % x + y)


import math
T = int(input())
for _ in range(T):
	(x, y, n) = map(int, input().split())
	ni = n
	n = math.floor(n / x)
	ans = x * n + y
	if ans > ni:
		print(ans - x)
	elif ans < 0:
		print(0)
	else:
		print(ans)


amountTests = int(input())
ans = ''
for x in range(amountTests):
	(x, y, n) = [int(x) for x in input().split()]
	maxMult = int(n / x)
	while x * maxMult + y > n:
		maxMult -= 1
	ans += str(x * maxMult + y) + '\n'
print(ans)


import math
t = int(input())
while t:
	[x, y, n] = list(map(int, input().split()))
	q = math.floor((n - y) / x)
	ans = q * x + y
	print(ans)
	t -= 1


from sys import stdin
n = int(stdin.readline())
for _ in range(n):
	(x, y, z) = map(int, stdin.readline().split())
	z = z - y
	m = z // x
	m = m * x + y
	print(m)


test = int(input())
for i in range(test):
	(x, y, n) = map(int, input().split())
	ans = n // x * x + y
	while ans > n:
		ans -= x
	print(ans)


def find(x, y, n):
	if n % x >= y:
		k = x * (n // x) + y
	else:
		k = x * (n // x - 1) + y
	return k
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	print(find(x, y, n))


import math
for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	p = math.floor((n - y) / x)
	k = p * x + y
	print(k)


t = int(input())
for i in range(t):
	l = []
	(x, y, n) = list(map(int, input().split()))
	k = n % x
	if k < y:
		p = x - y
		print(n - k - x + y)
	elif k == y:
		print(n)
	else:
		print(n - k + y)


tc = int(input())
while tc:
	(x, y, n) = map(int, input().split())
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))
	tc -= 1


t = int(input())
while t:
	z = list(map(int, input().split()))
	b = z[2] % z[0]
	if b > z[1]:
		print(z[2] - (b - z[1]))
	elif b < z[1]:
		print(z[2] - (b + (z[0] - z[1])))
	else:
		print(z[2])
	t -= 1


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	r = n % x
	k = r - y
	if k < 0:
		k += x
	print(n - k)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	val = n % x
	if val == y:
		print(n)
	elif val < y:
		n = n - val - 1
		x -= 1
		remain = x - y
		print(n - remain)
	else:
		n = n - (val - y)
		print(n)


for x in range(int(input())):
	(x, y, n) = map(int, input().split())
	cos = (n - y) // x
	print(cos * x + y)


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
krish = 1000
ans = krish - 900
res = ans - 90
t = int(input())
for _ in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	c = n // x
	if c * x + y <= n:
		print(c * x + y)
	else:
		j = 1
		while (c - j) * x + y > n:
			j += 1
		print((c - j) * x + y)
	ans += 1


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(x, y, n) = input_split()
	a = (n - y) // x
	ans = a * x + y
	answers.append(ans)
print(*answers, sep='\n')


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	modRn = n % x
	if modRn == y:
		print(n)
	elif modRn > y:
		print(n - (modRn - y))
	else:
		print(n - (x - y + n % x))


t = int(input())
for j in range(t):
	(x, y, n) = map(int, input().split())
	n -= y
	print(x * (n // x) + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	rem = n % x
	num = n // x
	if rem == y:
		print(n)
	else:
		while num >= 0:
			if num * x + y <= n:
				print(num * x + y)
				break
			num -= 1


t = int(input())
for i in range(t):
	(m, n, k) = map(int, input().split())
	d = k // m
	ans = m * d + n
	while ans > k:
		d = d - 1
		ans = m * d + n
	print(ans)


import math
for w in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	aux = n % x
	if aux == y:
		print(n)
	elif aux > y:
		print(int(abs(abs(aux - y) - n)))
	else:
		aux2 = abs(y - x)
		print(int(abs(aux - n) - aux2))


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	t = n % x
	if t == y:
		print(n)
	elif t > y:
		print(n - (t - y))
	elif t < y:
		print(n - (t + abs(x - y)))


n = int(input())
for i in range(n):
	(x, y, z) = map(int, input().split())
	if z % x >= y:
		print(z // x * x + y)
	else:
		print((z // x - 1) * x + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		print(n - (r - y))
	else:
		d = n // x - 1
		print(d * x + y)


from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
	l = list(map(int, stdin.readline().strip().split(' ')))
	x = l[0]
	y = l[1]
	n = l[2]
	if n // x * x + y > n:
		print(n // x * x + y - x)
	else:
		print(n // x * x + y)


t = int(input())
while t > 0:
	t -= 1
	s = str(input())
	d = s.split()
	x = int(d[0])
	y = int(d[1])
	n = int(d[2])
	w = n
	z = n % x
	n -= z
	n += y
	while n > w:
		n -= x
	print(n)


t = int(input())
for h in range(t):
	(x, y, n) = [int(i) for i in input().split(' ')]
	f = n // x
	f *= x
	f += y
	if f > n:
		f -= x
	print(f)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	l = inlt()
	x = l[0]
	y = l[1]
	n = l[2]
	p = n % x
	res = (p - y) % x
	print(n - res)


tea = int(input())
for _ in range(tea):
	(ex, why, en) = map(int, input().split())
	are = en % ex
	if are > why:
		print(en - (are - why))
	elif are == why:
		print(en)
	else:
		print(en - (ex - (why - are)))


t = int(input())
l = [[int for i in range(3)] for i in range(t)]
for i in range(t):
	l[i] = list(map(int, input().split()))
for i in range(t):
	a = l[i][2] % l[i][0]
	if a > l[i][1]:
		print(l[i][2] - a + l[i][1])
	elif a == l[i][1]:
		print(l[i][2])
	else:
		print(l[i][2] - a - l[i][0] + l[i][1])


Test = int(input())
for i in range(Test):
	(x, y, n) = map(int, input().split(' '))
	subtract = n - y
	quotient = subtract // x
	k = x * quotient + y
	if k >= 0 and k <= n:
		print(k)


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
import math
t = int(input())
for tc in range(t):
	(x, y, n) = list(map(int, stdin.readline().split()))
	w1 = math.floor(n / x) * x + y
	w2 = (math.floor(n / x) - 1) * x + y
	if w1 <= n:
		res = w1
	else:
		res = w2
	stdout.write(str(res) + '\n')


import math

def find(x, y, n):
	a = math.ceil(n / x)
	for i in range(a, -1, -1):
		temp = i * x + y
		if temp <= n and temp % x == y:
			return i * x + y
	return 0
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split(' '))
	print(find(x, y, n))


def solve():
	(x, y, n) = list(map(int, input().split()))
	n -= y
	res = n // x
	print(res * x + y)
for _ in range(int(input())):
	solve()


m = int(input())
for j in range(m):
	(p, q, r) = map(int, input().split())
	print((r - q) // p * p + q)


t = int(input())
for you in range(t):
	l = input().split()
	x = int(l[0])
	y = int(l[1])
	n = int(l[2])
	z = (n - y) // x
	print(z * x + y)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	tinn = 1
	tinn = int(input())
	for tin in range(tinn):
		(x, y, n) = map(int, input().split())
		ans = (n - y) // x
		print(ans * x + y)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = map(int, input().split())
		nx = n % x
		diff = nx - y
		if diff < 0:
			n -= x
		print(n - diff)
main()


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a == y:
		print(n)
	elif n - a + y <= n:
		print(max(n - a + y, 0))
	elif n - a + y > n:
		print(max(n - a + (y - x), 0))


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	k = n
	while k % x != y:
		r = k % x
		if r > y:
			k = n - (r - y)
		elif r < y:
			k = n - (x - (y - r))
	print(k)
	t = t - 1


t = int(input())
while t:
	(a, b, c) = map(int, input().split())
	z = c - b
	zz = z // a
	print(a * zz + b)
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def solution(x, y, n):
	near = n // x * x
	if near == 0:
		write(y)
	elif near + y <= n:
		write(near + y)
	else:
		write(near - (x - y))

def main():
	for _ in range(r_int()):
		(x, y, n) = r_array()
		solution(x, y, n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


m = int(input())
while m:
	m -= 1
	(x, y, n) = map(int, input().split())
	o = n // x * x + y
	if o > n:
		o -= x
	print(o)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	ans = y
	n = n - y
	ans += n // x * x
	print(ans)


from sys import stdout
import math, re
t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	k -= b
	num = k // a
	print(num * a + b)


tc = int(input())
for _ in range(tc):
	(x, y, n) = list(map(int, input().split()))
	rem = n // x
	maxx = rem * x
	if maxx + y > n:
		maxx = (rem - 1) * x
		print(maxx + y)
	else:
		print(maxx + y)


a = input()
for x in range(int(a)):
	b = input().split(' ')
	ans = int(b[2]) // int(b[0]) * int(b[0]) + int(b[1])
	if ans > int(b[2]):
		print(ans - int(b[0]))
	else:
		print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().strip().split())
	m = int(n / x)
	k = m * x + y
	if k > n:
		k = k - x
	print(k)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	x = a[0]
	y = a[1]
	n = a[2]
	k = n % x
	if k > y:
		answer = n - (k - y)
	elif k == y:
		answer = n
	else:
		answer = n - (x + k - y)
	print(answer)


def solution(x, y, n):
	current = n % x
	if y <= current:
		print(n - current + y)
		return
	else:
		print(n - current - x + y)
inp = int(input())
for _ in range(inp):
	(x, y, n) = tuple(map(int, input().split()))
	solution(x, y, n)


import math
t = int(input())
valores = []
for i in range(t):
	(x, y, n) = map(int, input().split())
	div = n // x
	mod = n % x
	resultado = y - mod
	if resultado < 0:
		valores.append(n + resultado)
	elif resultado == 0:
		valores.append(n)
	else:
		valores.append(n - x + resultado)
for i in valores:
	print(i)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(x, y, n):
	d = n // x
	ans = d * x + y
	if ans > n:
		ans -= x
	return ans

def main():
	for _ in range(ri()):
		(x, y, n) = ria()
		wi(solve(x, y, n))
main()


import collections
import math
import sys
import itertools
import itertools

def sa(Type=int):
	return [Type(x) for x in input().split()]

def solve(t):
	(x, y, n) = sa()
	c = (n - y) // x
	print(x * c + y)
t = int(input())
for i in range(t):
	solve(i + 1)


t = int(input())
while t > 0:
	(x, y, n) = list(map(int, input().split()))
	d = n // x
	if n - d * x >= y:
		print(d * x + y)
	else:
		print((d - 1) * x + y)
	t -= 1


m = int(input())
i = 0
while i < m:
	s = [int(x) for x in input().split()]
	(x, y, n) = (s[0], s[1], s[2])
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		t = n - n % x + y
		while t > n:
			t -= x
		print(t)
	i += 1


t = int(input())
for t in range(t):
	(x, y, n) = [int(s) for s in input().split()]
	ans = int(n / x) * x + y
	if ans > n:
		ans -= x
	print(ans)


n = int(input())
for x in range(n):
	(x, y, z) = [int(x) for x in input().split()]
	ans1 = z - y
	ans1 = ans1 // x
	ans = ans1 * x + y
	print(ans)


import math
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	print(x * ((n - y) // x) + y)


t = int(input())
for _ in range(t):
	(x, y, k) = map(int, input().split())
	d = k // x
	ans = x * d + y
	while ans > k:
		d = d - 1
		ans = x * d + y
	print(ans)


n = input('')
n = int(n)
matrix = []
for i in range(n):
	entries = list(map(int, input().split()))
	matrix.append(entries)
for i in range(n):
	t_mat = matrix[i]
	x = t_mat[0]
	y = t_mat[1]
	m = t_mat[2]
	maxx = int(m / x)
	flag = 1
	while flag == 1 and maxx >= 0:
		if x * maxx + y <= m:
			print(x * maxx + y)
			flag = 0
		else:
			maxx = maxx - 1


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
dgnl = lambda x: sqrt(2 * x ** 2)
for _ in range(I()):
	(x, y, n) = R()
	if n % x >= y:
		print(n // x * x + y)
	else:
		print(max(0, (n // x - 1) * x + y))


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	num = n // x
	a = num * x + y
	while a % x != y or a > n:
		num -= 1
		a = num * x + y
	print(a)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	const = y + x * (n // x)
	p = 0
	k = n * 2
	while k > n:
		k = const - p * x
		p += 1
	print(k)


t = int(input())
nums = []
for i in range(t):
	nums.append([int(x) for x in input().split()])
output = []
for num in nums:
	x = num[0]
	y = num[1]
	n = num[2]
	k1 = n // x
	if k1 * x + y > n:
		k1 = k1 - 1
	k = k1 * x + y
	output.append(k)
for a in output:
	print(a)


import os, sys
from io import IOBase, BytesIO
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, sin
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outarr(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val):
	return [val for i in range(n)]

def l2d(n, m, val):
	return [l1d(m, val) for j in range(n)]
for _ in range(int(data())):
	(x, y, n) = sp()
	div = n // x
	if div * x + y <= n:
		out(div * x + y)
		continue
	div -= 1
	out(div * x + y)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	(x, y, n) = spin()
	a = n - y
	b = a // x
	print(b * x + y)


a = int(input(''))
for i in range(0, a):
	(a, b, c) = map(int, input().split())
	if c % a == b:
		print(c)
	else:
		x = c % a
		if x < b:
			c = c - x
			y = a - b
			c = c - y
			print(c)
		else:
			x -= b
			print(c - x)


k = int(input())
for i in range(k):
	(x, y, n) = [int(inp) for inp in input().split()]
	nmod = n % x
	ymod = y % x
	if nmod >= ymod:
		print(n - (nmod - ymod))
	else:
		print(n - x - (nmod - ymod))


def get_number(x, y, n):
	r = n % x
	if y == r:
		return n
	if y < r:
		return n - (r - y)
	if y > r:
		return n - x + (y - r)
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	print(get_number(x, y, n))


for _ in range(int(input())):
	(x, y, n) = list((int(x) for x in input().split()))
	m = n % x
	if m == y:
		print(n)
	elif m > y:
		print(n - (m - y))
	else:
		print(n - x + (y - m))


t = int(input())

def process():
	[x, y, n] = list(map(int, input().split(' ')))
	a = int((n - y) * 1.0 / x)
	print(a * x + y)
for _ in range(t):
	process()


rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))
INF = float('inf')

def solve(X, Y, N):
	if N % X == Y:
		return N
	diff = N % X
	if diff > Y:
		return N - (diff - Y)
	else:
		return N - diff - (X - Y)
t = rri()
for _ in range(t):
	(x, y, n) = rrm()
	print(solve(x, y, n))


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	(x, y, n) = map(int, stdin.readline().split())
	q = n // x
	k = x * q + y
	if k > n:
		k -= x
	print(k)


def process():
	(x, y, n) = map(int, input().split())
	quot = n // x
	rem = n % x
	if rem < y:
		quot -= 1
	print(quot * x + y)
for i in range(int(input())):
	process()


t = int(input())
l = []
for x in range(t):
	l.append([int(w) for w in input().split()])
for element in l:
	n = True
	if element[2] - element[2] % element[0] + element[1] <= element[2]:
		print(element[2] - element[2] % element[0] + element[1])
	else:
		print(element[2] - element[2] % element[0] - (element[0] - element[1]))


def req_rem(arr):
	x = arr[0]
	y = arr[1]
	n = arr[2]
	rem = n % x
	if rem == y:
		return n
	elif rem < y:
		ans = n - x + (y - rem)
	elif rem > y:
		ans = n - (rem - y)
	return ans
t = int(input())
for _ in range(t):
	arr = list(map(int, input().split()))
	print(req_rem(arr))


numb = int(input())
for n in range(numb):
	word = str(input()).split(' ')
	rem = int(word[1])
	bi = int(word[2])
	sm = int(word[0])
	if bi % sm == rem:
		print(bi)
	elif bi % sm > rem:
		print(bi - (bi % sm - rem))
	else:
		print(bi + (rem - bi % sm) - sm)


T = int(input())
for i in range(T):
	(x, y, n) = map(int, input().split())
	if n % x < y:
		a = n % x
		b = y - a
		c = x - b
		print(n - c)
	else:
		a = n % x
		b = a - y
		print(n - b)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	x = l[0]
	y = l[1]
	n = l[2]
	num = n // x * x
	if num <= n - y:
		print(num + y)
	else:
		num -= x
		print(num + y)


t = int(input())
for q in range(t):
	(x, y, n) = list(map(int, input().split(' ')))
	if n % x == y:
		print(n)
	else:
		a = n // x * x + y
		b = (n // x - 1) * x + y
		if a <= n and b <= n:
			print(max(a, b))
		else:
			print(min(a, b))


t = eval(input())
for i in range(0, t):
	(x, y, n) = map(int, input().split())
	k = n - (n - y) % x
	print(k)


import math
t = int(input())
for w in range(t):
	array = list(map(int, input().split()))
	x = array[0]
	y = array[1]
	n = array[2]
	n_mod = n % x
	subtraction = (n_mod - y) % x
	print(n - subtraction)


import sys
import math
from sys import stdin, stdout
from collections import deque, defaultdict
from math import ceil, floor, inf, sqrt, factorial, gcd, log2
from copy import deepcopy
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
for _ in range(ii1()):
	(x, y, n) = iia()
	N = n
	a = n % x
	n -= a
	if n + y <= N:
		print(n + y)
	elif n - (x - y) >= 0:
		print(n - (x - y))
	else:
		print(0)


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	res = n // x * x + y
	if not res <= n:
		res -= x
	print(res)
	t -= 1


t = int(input())
while t > 0:
	(x, y, n) = map(int, input().rstrip().split())
	if n % x == y:
		print(n)
	elif n % x > y:
		print(n - (n % x - y))
	else:
		print(n - n % x - (x - y))
	t -= 1


n = int(input())
results = []
for _ in range(n):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	r = n % x
	if r == y:
		results.append(n)
	elif r < y:
		res = n - x + (y - r)
		results.append(res)
	elif r > y:
		res = n - (r - y)
		results.append(res)
for r in results:
	print(r)


import math
t = int(input())

def fun(x, y, n):
	a = math.floor((n - y) / x)
	ans = a * x + y
	print(int(ans))
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	fun(x, y, n)


t = int(input())
for i in range(t):
	(x, y, n) = [int(j) for j in input().split()]
	if n - n % x + y <= n:
		print(n - n % x + y)
	elif n - n % x - (x - y) <= n:
		print(n - n % x - (x - y))


import sys

def input():
	return sys.stdin.readline()

def print(x):
	sys.stdout.write(x)
t = int(input())
for _ in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	print(str((n - y) // x * x + y))
	print('\n')


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	start = n - 2 * y
	res = 0
	if n < x:
		res = y
	elif n % x == y:
		res = n
	else:
		c = n // x
		res = c * x + y
		if res >= n:
			c = n // x
			c -= 1
			res = c * x + y
	print(res)


def solve():
	[x, y, n] = map(int, input().split())
	k = (n - y) // x * x + y
	return k
for _ in range(int(input())):
	print(solve())


from sys import stdin
sdaf = int(stdin.readline())
for _ in range(sdaf):
	(asdfsafg, yue, ouuoi) = map(int, stdin.readline().split())
	ouuoi = ouuoi - yue
	oipop = ouuoi // asdfsafg
	oipop = oipop * asdfsafg + yue
	print(oipop)


def inner(x, y, n):
	mod = n % x
	if y == mod:
		return n
	elif y < mod:
		return n - (mod - y)
	else:
		return n - (mod + (x - y))

def mod():
	list1 = []
	list2 = []
	a = input()
	for i in range(int(a)):
		a = input()
		a = [int(i) for i in a.split(' ')]
		list1.append(a)
	for i in list1:
		k = inner(i[0], i[1], i[2])
		list2.append(str(k))
	return '\n'.join(list2)
print(mod())


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = (n - y) // x
	k = 0
	k = x * ans + y
	print(int(k))


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	(x, y, n) = ilele()
	f = n // x
	x1 = f * x + y
	x2 = (f - 1) * x + y
	if x1 <= n:
		print(x1)
	else:
		print(x2)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def foo():
	(x, y, n) = invr()
	a = x + y
	b = (n - a) // x
	ans = a + x * b
	print(ans)
t = inp()
for i in range(t):
	foo()


t = int(input())
a = []
for i in range(t):
	a.append([])
	a[i] = [int(a[i]) for a[i] in input().split()]
res = []
for i in range(t):
	x = a[i][0]
	y = a[i][1]
	n = a[i][2]
	p = n % x
	if p == y:
		res.append(n)
	elif p > y:
		res.append(n - (p - y))
	else:
		res.append(n - p - x + y)
for i in range(t):
	print(res[i])


t = int(input())
i = 0
while i < t:
	r = []
	(x, y, n) = [int(x) for x in input().split()]
	e = (n - y) // x
	print(e * x + y)
	i += 1


try:
	t = int(input())
	for i in range(t):
		(x, y, n) = map(int, input().split())
		d = n // x
		r = n % x
		n1 = n - r
		r1 = n1 + y
		if r1 > n:
			r1 = r1 - x
		print(r1)
except:
	pass


import math
t = int(input())
for _ in range(t):
	(x, y, z) = map(int, input().split())
	w = z % x
	if w == y:
		print(z)
	elif y == 0:
		if z >= x:
			print(z - z % x)
		elif z < x:
			print(0)
	else:
		p = z % x
		if p < y:
			print(z - (x - abs(y - p)))
		else:
			print(z - abs(y - p))


import sys
sys.setrecursionlimit(10 ** 9)
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = (n - y) // x * x + y
	print(ans)


t = int(input())
for case in range(t):
	(x, y, n) = [int(z) for z in input().split()]
	n -= y
	print(n // x * x + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	d = n // x
	c = d * x
	if c + y <= n:
		print(c + y)
	elif c % x == y:
		print(c)
	else:
		print(c - x + y)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def getlistofstring():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
for _testcases_ in range(int(input())):
	(x, y, n) = get_ints()
	fac = n // x
	ans = fac * x + y
	while ans > n:
		fac -= 1
		ans = fac * x + y
	print(ans)


N = int(input())
for i in range(N):
	a = list(map(int, input().strip().split()))
	x = a[0]
	y = a[1]
	n = a[2]
	rslt = n % x
	if rslt > y:
		print(n - (rslt - y))
	elif rslt < y:
		print((n // x - 1) * x + y)
	else:
		print(n)


def find_divident(num, num2):
	return num // num2

def find_max_required_reminder(x, a, b, c):
	while True:
		y = x * a + b
		if y <= c:
			return y
		else:
			x = x - 1

def main():
	test_case = int(input())
	while test_case != 0:
		(a, b, c) = map(int, input().split())
		x = find_divident(c, a)
		res = find_max_required_reminder(x, a, b, c)
		print(res)
		test_case = test_case - 1
main()


for t in range(int(input())):
	(x, y, n) = map(int, str(input()).strip().split())
	q = int(n / x) * x
	if q + y == n:
		print(n)
	elif q + y < n:
		print(q + y)
	else:
		print(q - (x - y))


n = int(input())
for i in range(n):
	(n, m, p) = map(int, input().split())
	if p - p % n + m <= p:
		print(p - p % n + m)
	else:
		print(p - p % n - n + m)


def solve():
	(x, y, n) = [int(v) for v in input().split()]
	v = n // x
	ans = v * x + y
	if ans > n:
		ans -= x
	print(ans)
t = int(input())
for _ in range(t):
	solve()


def main():
	(x, y, n) = map(int, input().split())
	return (n - y) // x * x + y
t = int(input())
for i in range(t):
	print(main())


def solve(x, y, n):
	a = n - n % x + y
	b = n - n % x - (x - y)
	if a <= n:
		return a
	else:
		return b
testcase = int(input())
for i in range(testcase):
	(x, y, n) = map(int, input().split())
	print(solve(x, y, n))


t = int(input())
for i in range(t):
	(a, b, c) = list(map(int, input().split()))
	(x, y, n) = (a, b, c)
	aise = pow(n, 1, x)
	if aise > y:
		print(max(n - aise + y, 0))
	else:
		jkl = 0
		if aise == y:
			print(n)
		else:
			print(n - x - aise + y)


def lar(x, y, z):
	if x > z:
		return -1
	val = z - x
	div = (z - x) // y
	ans = div * y + x
	return ans
for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	print(lar(y, x, n))


size = int(input())
(x, y, n) = ([], [], [])
i = 0
while i < size:
	tmp = input().split(' ')
	x.append(int(tmp[0]))
	y.append(int(tmp[1]))
	n.append(int(tmp[2]))
	i += 1
i = 0
while i < size:
	if n[i] % x[i] < y[i]:
		print(n[i] - x[i] + y[i] - n[i] % x[i])
	elif n[i] % x[i] == y[i]:
		print(n[i])
	else:
		print(n[i] - (n[i] % x[i] - y[i]))
	i += 1


t = int(input())
for i in range(t):
	a = input().split()
	a = list(map(int, a))
	l = 0
	r = a[2] // a[0] + 1
	t = 0
	while l <= r:
		t = (l + r) // 2
		if t * a[0] + a[1] <= a[2]:
			l = t + 1
		else:
			r = t - 1
	print((l - 1) * a[0] + a[1])


t = int(input())
for loop in range(t):
	(x, y, n) = map(int, input().split())
	roger = n % x
	if roger == y:
		print(n)
	elif roger < y:
		print(n - x + abs(roger - y))
	else:
		print(n - abs(roger - y))


from sys import stdin, stdout, setrecursionlimit
from math import ceil
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	ok = n % x
	ok = ok + x - y
	ok %= x
	print(n - ok)


def solve(x, y, n):
	br = n // x
	if br * x + y <= n:
		return br * x + y
	else:
		return br * x - (x - y)
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	print(solve(x, y, n))


def findk(x, y, n):
	if n % x >= y:
		ans = n - (n % x - y)
	else:
		ans = n - (n % x + x - y)
	return ans
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	print(findk(x, y, n))


z = input
from math import ceil, log, gcd
n1 = int(z())
for _ in range(n1):
	(x, y, n) = list(map(int, z().split()))
	t = n // x
	rem = n % x
	if rem > y:
		print(n - abs(rem - y))
	elif rem < y:
		print(n - x + abs(rem - y))
	else:
		print(n)


it = lambda : list(map(int, input().strip().split()))

def solve():
	(x, y, n) = it()
	a = n // x * x + y
	while a > n:
		a -= x
	print(a)
T = int(input())
for _ in range(T):
	solve()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	rem = n % x
	ans = n - rem
	a = ans + y
	b = ans - (x - y)
	if a >= 0 and a <= n:
		print(a)
	else:
		print(b)


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	(x, y, n) = map(int, inp().split())
	val = n + y - n % x
	while val > n:
		val -= x
	print(val)


t = int(input())
for i in range(t):
	(x, y, n) = [int(g) for g in input().split()]
	if n < x:
		print(y)
		continue
	div = n // x
	modo = div * x + y if div * x + y <= n else div * x - (x - y)
	print(modo)


for i in range(0, int(input())):
	(num1, num2, num3) = map(int, input().split(' '))
	print(num3 - (num3 - num2) % num1)


tests = int(input())
sol = []
while tests:
	tests -= 1
	(x, y, n) = (int(i) for i in input().split())
	h = n // x * x
	h += y
	while h > n:
		h -= x
	sol.append(h)
for i in sol:
	print(i)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	n1 = n - n % x
	n1 = n1 + y
	if n1 > n:
		n1 -= x
	print(n1)


from sys import stdin
a = int(stdin.readline())
for i in range(0, a):
	[x, y, n] = stdin.readline().split()
	x = int(x)
	y = int(y)
	n = int(n)
	k = n // x * x
	k += y
	while k > n:
		k -= x
	print(k)


def f(x, y, n):
	rem = n % x
	if rem == y:
		return n
	if n <= x:
		return y
	if rem > y:
		return n - (rem - y)
	else:
		return n - (rem + x - y)
n = int(input())
for _ in range(n):
	(x, y, n) = [int(val) for val in map(int, input().strip().split())]
	print(f(x, y, n))


n = int(input())
for _ in range(n):
	inp = input().split(' ')
	x = int(inp[0])
	y = int(inp[1])
	n = int(inp[2])
	a = n // x
	while a * x + y > n:
		a -= 1
	print(a * x + y)


tests = int(input())
for i in range(tests):
	arr = [int(i) for i in input().split()]
	num_range = arr[2]
	remainder = arr[1]
	div = arr[0]
	key = num_range % div
	if key == remainder:
		print(num_range)
	elif key < remainder:
		result = num_range - key - (div - remainder)
		print(result)
	else:
		result = num_range - (key - remainder)
		print(result)


for i in range(int(input())):
	(x, y, n) = [int(k) for k in input().split()]
	diff = n % x
	if diff >= y:
		print(n - (diff - y))
	else:
		print(n - diff - x + y)


for i in range(int(input())):
	(x, y, n) = [int(c) for c in input().split()]
	k = n
	k -= (n - y) % x
	print(k)


def solve():
	(x, y, n) = input().split()
	return (int(n) - int(y)) // int(x) * int(x) + int(y)
t = int(input())
for _ in range(t):
	print(solve())


test_case = int(input())
for j in range(test_case):
	(x, y, n) = list(map(int, input().split(' ')))
	d = n // x
	if x * d + y > n:
		print(x * (d - 1) + y)
	else:
		print(x * d + y)


import math
t = int(input())
while t != 0:
	t -= 1
	(x, y, n) = map(int, input().split())
	multiplier = math.floor(n / x)
	if multiplier * x + y > n:
		ans = (multiplier - 1) * x + y
		print(ans)
	else:
		ans = multiplier * x + y
		print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		amari = n % x
		if amari >= y:
			print(n - (amari - y))
		else:
			print(n - (x - abs(y - amari)))


nTests = int(input())
for _ in range(nTests):
	(mod, rem, top) = [int(x) for x in input().split()]
	topMod = top % mod
	less = (topMod - rem) % mod
	print(top - less)


for i in range(int(input())):
	(x, y, k) = map(int, input().split())
	ans = k % x
	if ans != y:
		if ans < y:
			ans = ans + x - y
		else:
			ans = ans - y
		print(k - ans)
	else:
		print(k)


t = int(input())
for i in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	p = (n - y) // x
	print(p * x + y)


import math
t = int(input())
for g in range(t):
	(x, y, n) = map(int, input().split())
	a = n // x * x
	if y == 0 and n < x:
		print(0)
		continue
	if n - a == y:
		print(n)
	elif n % x >= y:
		print(a + y)
	else:
		print(a - x + y)


test = int(input())
test_arr = []
for _ in range(test):
	(x, y, n) = map(int, input().split())
	num = n // x
	k = num * x + y
	if k > n:
		k = num * x - (x - y)
	test_arr.append(k)
for t in test_arr:
	print(t)


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def solve():
	for _ in range(int(sys.stdin.readline())):
		(x, y, n) = map(int, sys.stdin.readline().split())
		nn = n
		n = x * (n // x)
		if n + y <= nn:
			print(n + y)
		else:
			print(n - x + y)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	mxmult = n // x * x
	if mxmult + y <= n:
		print(mxmult + y)
	else:
		print((n // x - 1) * x + y)


m = int(input())
for i in range(0, m):
	h = str(input()).split()
	(x, y, n) = (int(h[0]), int(h[1]), int(h[2]))
	k = int(n / x) * x
	ans = k + y
	while ans > n:
		ans -= x
	print(ans)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	(x, y, n) = mInt()
	if n % x > y:
		print(n - (n % x - y))
	elif n % x == y:
		print(n)
	else:
		print(n - x + (y - n % x))


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def sumofdigits(n):
	return sum([int(i) for i in str(n)])
for _ in range(iinput()):
	(x, y, n) = rinput()
	print(n - (n - y) % x)


def main():
	for t in range(int(input())):
		(x, y, n) = map(int, input().split())
		if n % x >= y:
			print(n - (n % x - y))
		else:
			print(n - (n % x + 1) - (x - 1 - y))
main()


import math
t = int(input())
for _ in range(t):
	(x, y, n) = tuple(map(int, input().split()))
	if n < x:
		print(y)
	else:
		print(math.floor((n - y) / x) * x + y)


t = int(input())
i = 0
while i < t:
	string = input()
	(x, y, n) = string.split()
	x = int(x)
	y = int(y)
	n = int(n)
	k = n % x
	if k < y:
		n = n - (k + x) + y
	else:
		n = n - (k - y)
	print(n)
	i += 1


import math

def facts(n):
	ans = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			ans.append(i)
			ans.append(n // i)
	ans = sorted(ans)
	return ans
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	val = n // x * x + y
	if val > n:
		val -= x
	print(val)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	m = n % x
	if m == y:
		print(n)
	elif m > y:
		print(n - (m - y))
	else:
		temp = n - m
		res = temp - (x - y)
		print(res)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		[x, y, n] = inlt()
		a = (n - y) // x
		k = x * a + y
		print(k)
main()


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(x, y, n) = mp()
	a = n % x
	if a == y:
		pr(n)
	elif a > y:
		z = a - y
		pr(n - z)
	else:
		b = x - y
		pr(n - a - b)
for _ in range(inp()):
	solve()


from sys import stdin as lector
input = lector.readlines()
for i in range(1, int(input[0]) + 1):
	(x, y, n) = list(map(int, input[i].split(' ')))
	if n % x > y:
		n = n - (n % x - y)
	elif n % x < y:
		n = n - n % x - (x - y)
	print(n)


import math
test = int(input())
for i in range(test):
	val = input()
	val = val.split()
	x = int(val[0])
	y = int(val[1])
	n = int(val[2])
	div = math.ceil(n / x)
	k = x * div + y
	while k > n:
		k -= x
	print(k)


for i in range(int(input())):
	X = list(map(int, input().split()))
	Ans = 0
	if X[-1] % X[0] >= X[1]:
		Ans = X[-1] - (X[-1] % X[0] - X[1])
	else:
		Ans = max(X[-1] - (X[0] - X[1] + X[-1] % X[0]), X[1])
	print(Ans)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	r = n % x
	ans = 0
	if r >= y:
		ans = n - (r - y)
	else:
		n -= r
		ans = n - (x - y)
	print(ans)


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	for a in range(n // x, -1, -1):
		a *= x
		a += y
		if a <= n:
			print(a)
			break


def ans(x, y, n):
	a = (n - y) // x
	return a * x + y
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	print(ans(x, y, n))


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	tmp = n // x
	tmp = tmp * x
	if tmp + y <= n:
		print(tmp + y)
	else:
		print(max(y, tmp - x + y))


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	num = n - y
	r = num % x
	z = (num - r) // x
	print(x * z + y)


t = int(input())
x = []
y = []
n = []
for i in range(t):
	(xt, yt, nt) = map(int, input().split())
	x.append(xt)
	y.append(yt)
	n.append(nt)
for i in range(len(x)):
	f = int((n[i] - y[i]) / x[i])
	print(f * x[i] + y[i])


a = int(input())
for x in range(a):
	(b, c, d) = map(int, input().split())
	if d % b == c:
		print(d)
	elif d % b > c:
		print(d - (d % b - c))
	else:
		h = d // b
		g = b * h
		print(g - (b - c))


t = int(input())
nums = []
for i in range(t):
	nums.append([int(x) for x in input().split()])
output = []
for pairs in nums:
	x = pairs[0]
	y = pairs[1]
	n = pairs[2]
	newNum = n - y
	k = newNum // x
	output.append(k * x + y)
for num in output:
	print(num)


n_tests = int(input())
for j in range(n_tests):
	(x, y, n) = (int(x) for x in input().split())
	print((n - y) // x * x + y)


for test_i in range(int(input())):
	(x, y, n) = map(int, input().split())
	print((n // x - (1 if n % x < y else 0)) * x + y)


T = int(input())
for case in range(T):
	(x, y, n) = map(int, input().split())
	ans = (n - y) // x * x + y
	print(ans)


def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())

def main():
	for i in range(ii()):
		(x, y, n) = mi()
		r = n % x
		t = n - r
		if t + y <= n:
			print(t + y)
			continue
		if t + y > n:
			print(t + y - x)
			continue
main()


def find_k(x, y, n):
	return (n - y) // x * x + y
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	k = find_k(x, y, n)
	print(k)


for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = c % a
	if x < b:
		c -= x
		x = c // a - 1
		print(a * x + b)
	else:
		print(c - (x - b))


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	w = n % x
	if w >= y:
		print(n - (w - y))
	else:
		n -= w + 1
		print(n - (n % x - y))


n = int(input())
for i in range(n):
	c = 0
	(x, y, z) = input().split()
	n = (int(z) - int(y)) // int(x)
	print(n * int(x) + int(y))


t = int(input())
for i in range(t):
	s = input().split()
	x = int(s[0])
	y = int(s[1])
	n = int(s[2])
	minusMod = n - n % x + y
	if minusMod > n:
		print(minusMod - x)
	else:
		print(minusMod)


t = int(input())
for i in range(t):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	d = c // a * a
	if d + b > c:
		print(d - abs(a - b))
	else:
		print(b + d)


for z in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	ans = n // x * x
	ans += y
	if ans > n:
		ans -= x
	print(ans)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(x, y, n) = int_array()
	p = n // x * x + y
	while p > n:
		p -= x
	print(p)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	N = n
	if n % x == y:
		print(n)
	else:
		n -= n % x
		if n % x == y:
			print(n)
			continue
		diff = x - y
		if n + y < N and (n + y) % x == y:
			print(n + y)
			continue
		if (n - diff) % x == y:
			print(n - diff)
			continue


t = int(input())
l = []
for i in range(t):
	[x, y, n] = list(map(int, input().split()))
	max = (n - y) // x * x + y
	l.append(max)
for i in l:
	print(i)


t = int(input())
for _ in range(t):
	s = input().split()
	x = int(s[0])
	y = int(s[1])
	n = int(s[2])
	ans = x * (n // x) + y
	if ans > n:
		ans -= x
	print(ans)


a = int(input())
x = []
for i in range(a):
	b = input().split()
	x.append(b)
for j in x:
	tam_bolen = int(j[2]) // int(j[0])
	sonuc = tam_bolen * int(j[0]) + int(j[1])
	if sonuc <= int(j[2]):
		print(sonuc)
	else:
		sonuc = (tam_bolen - 1) * int(j[0]) + int(j[1])
		print(sonuc)


for _ in range(int(input())):
	(x, y, n) = [int(i) for i in input().split()]
	c = n % x
	if c == y:
		print(n)
	elif c < y:
		d = n // x
		d = d - 1
		print(d * x + y)
	else:
		d = c - y
		print(n - d)


import math
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	tmp = n % x
	if tmp == y:
		print(n)
	elif tmp > y:
		print(n - (tmp - y))
	else:
		print(n - tmp - x + y)


import sys
import random
from math import *

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

def rlinput():
	return list(map(int, input().split()))

def trinput():
	return tuple(rinput())

def srlinput():
	return sorted(list(map(int, input().split())))

def NOYES(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def YESNO(fl):
	if fl:
		print('YES')
	else:
		print('NO')

def main():
	(x, y, n) = rinput()
	res = n - y
	print(x * (res // x) + y)
for inytd in range(iinput()):
	main()


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	a = n // x
	b = a * x
	d = b + y
	if d > n:
		a = n // x
		b = (a - 1) * x
		d = b + y
	print(d)


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	s = n % x
	if s == y:
		k = n
	elif s > y:
		k = n - (s - y)
	else:
		k = n - s - (x - y)
	print(k)


def solve():
	(x, y, n) = map(int, input().split())
	rem = n % x
	sol = 0
	if rem < y:
		sol = x - y + rem
	else:
		sol = rem - y
	print(n - sol)
tc = int(input())
for i in range(tc):
	solve()


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	l = 0
	h = n
	m = 0
	d = n % x
	if d == y:
		print(n)
	elif d < y:
		n -= d
		n -= x - y
		print(n)
	else:
		d -= y
		n -= d
		print(n)


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
from collections import defaultdict
t = I()
for _ in range(t):
	(x, y, n) = M()
	r = n // x
	while x * r + y > n:
		r -= 1
	print(x * r + y)


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	(a, b, c) = map(int, stdin.readline().split())
	k = c // a
	k *= a
	k += b
	if k > c:
		k -= a
	stdout.write(str(k) + '\n')


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	(x, y, n) = rinput()
	multi = n // x
	ans = multi * x + y
	if ans <= n:
		print(ans)
	else:
		print((multi - 1) * x + y)


from sys import stdin

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def solve():
	(x, y, n) = ip()
	k = n - n % x
	if k + y <= n:
		return k + y
	else:
		return k - (x - y)
t = int(input())
for i in range(t):
	print(solve())


import sys

def getK(x, y, n):
	k = n // x * x
	yT = n % x
	if yT >= y:
		return k + y
	return k - x + y
data = sys.stdin.readlines()
data.pop(0)
for line in data:
	if not '' == line.rstrip():
		nums = line.rstrip().split(' ')
		print(getK(int(nums[0]), int(nums[1]), int(nums[2])))


from sys import stdin, stdout
import math
input = stdin.readline

def print(x='', y='', end='\n'):
	if y == '':
		stdout.write(str(x) + end)
	else:
		stdout.write(str(x) + ' ' + str(y) + end)

def solve():
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
		return
	c = n // x * x
	if c + y <= n:
		print(c + y)
	else:
		print(c - abs(y - x))
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	(x, y, n) = list(map(int, stdin.readline().rstrip().split()))
	if False:
		print(0)
		continue
	else:
		tmp = n % x
		if tmp >= y:
			ans = n - (tmp - y)
		else:
			ans = n - tmp + (-x + y)
		print(ans)


num = int(input())
res = []
for i in range(num):
	tc = input()
	a_list = tc.split()
	map_object = map(int, a_list)
	l = list(map_object)
	x = l[0]
	y = l[1]
	n = l[2]
	start = n % x
	if start < y:
		d = y - start
		ans = n - x + d
	elif start > y:
		d = start - y
		ans = n - d
	else:
		ans = n
	res.append(ans)
for elem in res:
	print(elem)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	temp = n // x * x
	tem = (n // x - 1) * x
	if temp + y <= n:
		print(temp + y)
	else:
		print(tem + y)


test = int(input())
while test != 0:
	(x, y, n) = map(int, input().split())
	u = n // x
	if u * x + y <= n:
		print(u * x + y)
	else:
		print((u - 1) * x + y)
	test = test - 1


t = int(input())
while t:
	q = list(map(int, input().split()))
	(x, y, n) = (q[0], q[1], q[2])
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		print(n - r + y)
	else:
		n = n - r - (x - y)
		if n < 0:
			print('0')
		else:
			print(n)
	t -= 1


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	num = n
	val = num // x
	mod = num % x
	if mod == y:
		print(num)
	elif mod > y:
		print(val * x + y)
	else:
		print((val - 1) * x + y)


t = int(input())
for q in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	p = n % x
	if p == y:
		print(n)
	elif p > y:
		print(n - p + y)
	else:
		print(n - p - x + y)


for _ in range(int(input())):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	a = n // x
	a = a * x + y
	if a > n:
		a -= x
	print(a)


t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		k = n % x
		a = 0
		if k < y:
			a = n - x + abs(k - y)
		else:
			a = n - abs(k - y)
		print(a)


t = int(input())
for e in range(t):
	(x, y, n) = [int(a) for a in input().split()]
	op = (n - y) // x
	res = op * x + y
	print(res)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	m = n % x
	if m == y:
		print(n)
		continue
	if m > y:
		print(n - (m - y))
		continue
	d = n - m
	if d % x == y:
		print(d)
		continue
	ans = d - (x - y)
	print(ans)


test = int(input())
while test > 0:
	(x, y, n) = map(int, input().split())
	k = n
	rem = n % x
	k -= rem
	if k + y > n:
		print(k - (x - y))
	else:
		print(k + y)
	test -= 1


t = int(input())
ans = []
for i in range(t):
	(x, y, n) = map(int, input().split())
	temp = n // x
	sol = temp * x + y
	if sol > n:
		sol -= x
	print()
	ans.append(str(sol))
print('\n'.join(ans))


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math
from collections import Counter
for _ in range(IN()):
	(x, y, n) = MAP()
	print((n - y) // x * x + y)


from sys import stdin, exit
input = stdin.readline

def i():
	return input()

def ii():
	return int(input())

def iis():
	return map(int, input().split())

def liis():
	return list(map(int, input().split()))

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(x, y, n) = iis()
	a = n // x * x + y
	if a > n:
		a -= x
	print(a)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(x, y, n) = list(map(int, stdin.readline().rstrip().split(' ')))
	q = n // x
	p = q * x
	if p + y > n:
		print(p - (x - y))
	else:
		print(p + y)


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for i in range(t):
	(x, y, n) = nii()
	p = n // x
	if p * x + y <= n:
		print(p * x + y)
	else:
		print((p - 1) * x + y)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	ab = z % x
	if ab == y:
		print(z)
	elif ab > y:
		print(z - (ab - y))
	else:
		print(z - (ab + (x - y)))


import sys
input = sys.stdin.readline
from math import ceil
answer = []
for kek in range(int(input())):
	(x, y, n) = map(int, input().split())
	s = (n // x + 1) * x + y
	while s > n:
		s -= x
	answer.append(s)
print(*answer, sep='\n')


tc = int(input())
while tc > 0:
	(x, y, n) = map(int, input().split())
	(q, r) = divmod(n, x)
	if r < y:
		q = max(q - 1, 0)
	print(q * x + y)
	tc -= 1


t = int(input())
a = []
for i in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	d = int(n / x)
	k = x * d + y
	if k > n:
		k = k - x
	a.append(k)
for x in a:
	print(x)


t = int(input())
otvet = []
for _ in range(t):
	(x, y, n) = map(int, input().split())
	ostatok = n % x
	if ostatok == y:
		otvet.append(n)
		continue
	elif ostatok < y:
		koef = x - (y - ostatok)
		otvet.append(n - koef)
	elif ostatok > y:
		koef = ostatok - y
		otvet.append(n - koef)
for i in range(t):
	print(otvet[i])


import math
import bisect
import sys
from collections import OrderedDict
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
T = inp()
for t in range(T):
	(x, y, N) = invr()
	a = N // x
	k = y
	b = x * a
	if N - b < y:
		b -= x
	print(b + y)


import os
from sys import stdin

def solve(tc):
	(x, y, n) = map(int, stdin.readline().split())
	d = n // x
	if n % x >= y:
		print(d * x + y)
	else:
		print(x * (d - 1) + y)
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


def f(x, y, n):
	r1 = n // x * x
	if r1 + y > n:
		return r1 - x + y
	return r1 + y
for i in range(int(input())):
	print(f(*map(int, input().split())))


test = int(input())
ans = []
for i in range(test):
	j = list(map(int, input().split()))
	x = j[0]
	y = j[1]
	n = j[2]
	c = n % x
	if c == y:
		ans.append(n)
	elif c > y:
		ans.append(n - (c - y))
	else:
		ans.append(n - (x - (y - c)))
for i in ans:
	print(i)


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		(a, b, n) = MP()
		if n % a == b:
			print(n)
		else:
			temp = n % a
			z = n
			z -= temp
			if b + z <= n:
				print(z + b)
			else:
				print(z - a + b)
solve()


t = input()
t = int(t)
while t > 0:
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	ans = int((n - y) / x)
	ans = ans * x + y
	print(ans)
	t = t - 1


line = input()
for c in range(1, int(line) + 1):
	arr = list(map(int, input().split()))
	k = arr[0] * (arr[2] // arr[0]) + arr[1]
	if k > arr[2]:
		print(k - arr[0])
	else:
		print(k)


from math import floor
t = int(input())
for T in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	a = floor((n - y) / x)
	k = y + a * x
	print(k)


from collections import defaultdict as dd

def solve():
	(x, y, n) = list(map(int, input().split()))
	if n % x >= y:
		print(n // x * x + y)
	else:
		print((n // x - 1) * x + y)
t = 1
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	z = n - y
	p = z % x
	ans = n - p
	print(ans)


def main():
	for _ in range(int(input())):
		(x, y, n) = map(int, input().split())
		k = n - n % x + y
		if k > n:
			k -= x
		print(k)
main()


cases = int(input())
for q in range(cases):
	(x, y, n) = list(map(int, input().split()))
	t = (n - y) // x
	print(t * x + y)


for x11 in range(int(input())):
	(x, y, n) = map(int, input().split())
	t = n // x
	rem = n % x
	if rem >= y:
		print(x * t + y)
	else:
		t = t - 1
		print(x * t + y)


def main(x, y, n):
	q = (n - y) // x
	re = q * x + y
	return re
t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	ans = main(x, y, n)
	print(ans)


t = int(input())
ans = []
for i in range(t):
	(x, y, n) = map(int, input().split())
	ans.append(n // x * x + y if n // x * x + y <= n else (n // x - 1) * x + y)
for i in range(t):
	print(ans[i])


t = int(input())
for test in range(0, t):
	(x, y, n) = input().split()
	alp = (int(n) - int(y)) // int(x)
	print(alp * int(x) + int(y))


test_case = int(input())
for i in range(test_case):
	(x, y, n) = map(int, input().split())
	rem = n % x
	if rem >= y:
		print(n // x * x + y)
	else:
		t = n // x * x
		t -= x
		print(t + y)


def brute_force(n, x, y):
	while n >= 0:
		if n % x == y:
			return n
		n -= 1
	return n

def improved(n, x, y):
	i = n // x
	while i >= 0:
		num = i * x + y
		if num <= n and num % x == y:
			return num
		i -= 1
	return i
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split(' '))
	i = n // x
	while i >= 0:
		num = i * x + y
		if num <= n and num % x == y:
			print(num)
			break
		i -= 1


num = int(input())
for x in range(num):
	(x, y, n) = [int(x) for x in input().split()]
	t = n % x
	if t < y:
		print(x * int(n / x - 1) + y)
	else:
		print(x * int(n / x) + y)


import sys
t = 1
t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, sys.stdin.readline().strip().split()))
	a = n // x * x + y
	b = (n // x - 1) * x + y
	if a <= n:
		print(a)
	else:
		print(b)


t = int(input())
for i in range(t):
	(x, y, z) = map(int, input().split())
	if z % x == y:
		print(z)
	elif z % x > y:
		res = z % x - y
		print(z - res)
	else:
		res = x - y
		z = z - z % x - res
		print(z)


import collections as cc
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(x, y, n) = I()
	temp = n // x * x
	if temp + y <= n:
		print(temp + y)
	else:
		print(temp - (x - y))


import sys
sys.setrecursionlimit(100000)

def read():
	return int(input())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
cas = read()
while cas:
	cas -= 1
	(x, y, n) = get_ints()
	k = (n - y) // x
	print(k * x + y)


for _t in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	m = n // x
	if n - x * m >= y:
		print(x * m + y)
	else:
		print(x * (m - 1) + y)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	cnt = (c - b) // a
	print(cnt * a + b)


for t in range(int(input())):
	(x, y, n) = map(int, input().rstrip().split())
	r = n % x
	if r >= y:
		k = n - (r - y)
	else:
		k = n - r - x + y
	print(k)


import math
from collections import Counter, deque
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()
mod = 10 ** 9 + 7

def s(a):
	print(' '.join(list(map(str, a))))

def solve():
	(x, y, n) = M()
	a = (n - y) // x
	print(a * x + y)
for i in range(I()):
	solve()


def solve():
	(x, y, n) = list(map(int, input().strip().split()))
	m = (n - y) // x
	k = m * x + y
	return k

def main():
	t = int(input())
	for i in range(t):
		print(solve())
main()


def func(x, y, n):
	temp = n // x
	if x * temp + y <= n:
		print(x * temp + y)
	else:
		ans = x * (temp - 1) + y
		print(ans)
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	func(x, y, n)


def fastWay(x, y, n):
	mod = n % x
	res = n - mod + y
	return n if mod == y else res if mod > y else res - x
n = int(input())
for i in range(n):
	[x, y, n] = list(map(int, input().split()))
	print(fastWay(x, y, n))


for test in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = n - n % x
	if ans + y <= n:
		print(ans + y)
	else:
		print(ans - x + y)


t = int(input())
for i in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	some = n - y
	some2 = some // x
	print(some2 * x + y)


n = int(input())
for _ in range(n):
	(x, y, n) = map(int, input().split())
	divdend = n // x
	res = x * divdend + y
	while res > n:
		divdend -= 1
		res = x * divdend + y
	print(res)


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		elif input_format == 6:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enum = enumerate

def solve():
	(x, y, n) = input(1)
	a = n % x
	b = n - a + y
	if b > n:
		b -= x
	out(b)
	return
for i in range(input(11)):
	solve()


import sys
inputlist = sys.stdin.readlines()
number_of_testcases = int(inputlist[0].strip())
for i in range(number_of_testcases):
	(x, y, n) = list(map(int, inputlist[i + 1].strip().split(' ')))
	divisor = n // x
	remainder = n % x
	if remainder < y:
		divisor = divisor - 1
	print(divisor * x + y)


n = int(input())
for test in range(n):
	(x, y, k) = list(map(int, input().split()))
	if k % x == y:
		print(k)
	else:
		m = k - k % x + y
		if m > k:
			m = m - x
		print(m)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = c // a
	e = d * a
	p = e + b
	if p > c:
		print(e - a + b)
	else:
		print(p)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n - y
	b = int(a / x)
	res = x * b + y
	print(res)


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n // x * x
	if a + y <= n:
		print(a + y)
	else:
		a = (n // x - 1) * x
		if 0 <= a + y <= n:
			print(a + y)
		else:
			print(0)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	if y == 0:
		if n < x:
			print('0')
			continue
	if n == 0:
		print('0')
		continue
	mod1 = n % x
	prod = n // x
	if mod1 == y:
		print(n)
		continue
	if y < mod1:
		print(n - (mod1 - y))
		continue
	ans = prod * x + y
	if ans <= n:
		print(ans)
		continue
	else:
		print((prod - 1) * x + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	result = n + (y - a)
	while result > n:
		result -= x
	print(result)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	rem = n // x
	while 1:
		if rem * x + y <= n:
			print(rem * x + y)
			break
		else:
			rem -= 1


for _ in range(int(input())):
	(x, y, k) = list(map(int, input().split()))
	a = k // x
	a1 = a * x + y
	a2 = (a - 1) * x + y
	ans = 0
	if a1 > k:
		ans = a2
	else:
		ans = a1
	print(ans)


t = int(input())
ans = []
for i in range(t):
	(x, y, n) = map(int, input().split())
	m = n % x
	if m == y:
		ans += [n]
	elif m < y:
		ans += [n - x + abs(m - y)]
	else:
		ans += [n - abs(m - y)]
print(*ans, sep='\n')


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(x, y, n) = map(int, stdin.readline().split())
	m = (n - y) // x
	ans = m * x + y
	stdout.write(str(ans) + '\n')


N = int(input())
for _ in range(0, N):
	(x, y, n) = list(map(int, input().split()))
	n = n - y
	tmpi = n // x
	print(tmpi * x + y)


test_case = int(input())
for j in range(test_case):
	(x, y, n) = [int(x) for x in input().split()]
	rem = n % x
	if rem == y:
		print(n)
	elif rem > y:
		print(n - (rem - y))
	else:
		print(n - rem - (x - y))


import math
testcases = int(input())
for i in range(testcases):
	(x, y, n) = map(int, input().strip().split(' '))
	p = math.floor(n / x) + 1
	z = p * x - (x - y)
	if z > n:
		print(z - x)
	else:
		print(z)


for t in range(int(input())):
	(x, y, n) = [int(x) for x in input().split()]
	r = n % x
	if r >= y:
		print(n - (r - y))
	else:
		print(n - (r + x - y))


def one_case():
	(x, y, n) = map(int, input().split())
	z = n // x * x
	if z + y <= n:
		print(z + y)
	else:
		print(z + y - x)
t = int(input())
for i in range(t):
	one_case()


nn = int(input())
l = []
while nn:
	(x, y, n) = map(int, input().split())
	if n % x == y:
		l.append(n)
	else:
		rem = n % x
		diff = y - rem
		if diff < 0:
			l.append(n + diff)
		else:
			l.append(n - x + diff)
	nn = nn - 1
for i in l:
	print(i)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
for _ in range(int(input())):
	(x, y, n) = [int(i) for i in input().split()]
	n1 = n // x * x
	if n1 + y <= n:
		print(n1 + y)
	else:
		print(n1 - x + y)


import math
p = int(input())
for __ in range(p):
	(x, y, n) = map(int, input().split())
	z = math.ceil((n - y) // x)
	print(z * x + y)


n = int(input())
for I in range(n):
	(x, y, z) = [int(x) for x in input().split()]
	if z % x == y:
		print(z)
	elif z % x > y:
		p = z // x * x + y
		print(p)
	else:
		p = (z // x - 1) * x + y
		print(p)


t = int(input())
ans_list = []
for i in range(t):
	solution_list = []
	z = [int(x) for x in input().split(' ')]
	x = z[0]
	y = z[1]
	n = z[2]
	a = n // x
	b = a * x + y
	if b <= n:
		ans_list.append(b)
	else:
		while b >= n:
			a = a - 1
			b = a * x + y
		ans_list.append(b)
for i in ans_list:
	print(i)


t = int(input())
for x in range(t):
	(x, y, n) = map(int, input().split())
	thing = n % x
	diff = x - y
	if thing == y:
		print(n)
	elif thing > y:
		newNum = n - (thing - y)
		print(newNum)
	else:
		newNum = n - thing - (x - y)
		print(newNum)


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	n1 = n
	s = n // x
	if s == 0:
		print(y)
	elif n % x == y:
		print(n1)
	else:
		f = x * s + y
		if f > n:
			print(x * (s - 1) + y)
		else:
			print(f)


for i in range(int(input())):
	l = list(map(int, input().split()))
	(x, y, n) = (l[0], l[1], l[2])
	if n % x < y:
		print(n - n % x - (x - y))
	else:
		print(n - (n % x - y))


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	temp = n // x
	res = temp * x + y
	if res > n:
		res = temp * x - (x - y)
	print(res)


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	value = 0
	temp = n % x
	if temp >= y:
		value = n - (temp - y)
	else:
		a = temp + (x - y)
		value = n - a
	print(value)
	t = t - 1


for t in range(int(input())):
	(x, y, n) = map(int, input().split(' '))
	p = int(n / x)
	for i in range(p, -1, -1):
		if i * x + y <= n:
			print(i * x + y)
			break


import math
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	o = n % x
	if o > y:
		print(n - o + y)
	elif o == y:
		print(n)
	else:
		print(n - o - (x - y))


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	aux = n - n % x
	if aux + y > n:
		aux -= x
	aux += y
	print(aux)


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		(x, y, n) = map(int, input().split())
		if n % x == y:
			print(n)
		else:
			z = n // x
			if n % x < y:
				z -= 1
			print(x * z + y)
solution()


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	z = n // x
	p = n % x
	if p >= y:
		print(z * x + y)
	else:
		print((z - 1) * x + y)


for _ in range(0, int(input())):
	(x, y, n) = map(int, input().strip().split())
	t = n - y
	res = t // x
	print(x * res + y)


def calculate(x, y, n):
	(q, r) = divmod(n, x)
	if r < y:
		q -= 1
	return q * x + y
t = int(input())
for i in range(0, t):
	(x, y, n) = map(int, input().split())
	print(calculate(x, y, n))


def solution(x, y, n):
	b = n % x
	if y > b:
		return n - b - x + y
	else:
		return n - b + y
t = int(input())
for i in range(t):
	[x, y, n] = [int(s) for s in input().split(' ')]
	print(solution(x, y, n))


def solve():
	(x, y, n) = list(map(int, input().split()))
	out = n % x
	if out > y:
		print(n - out + y)
	elif out == y:
		print(n)
	else:
		print(n - (x - (y - out)))
t = int(input())
for test in range(t):
	solve()


for _ in range(int(input())):
	(x, y, n) = map(int, input().strip().split())
	r = n % x
	n = n - r + y
	print(n) if r >= y else print(n - x)


for i in range(int(input())):
	a = input().split()
	b = int(a[0])
	c = int(a[1])
	d = int(a[2])
	e = d // b * b + c
	if e > d:
		print(e - b)
	else:
		print(e)


def func(n):
	for i in range(n):
		l = list(map(int, input().split()))
		x = l[0]
		y = l[1]
		z = l[2]
		mul = (z - y) // x
		ans = mul * x + y
		print(ans)
n = int(input())
func(n)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	q = n // x
	a1 = x * q + y
	if a1 <= n:
		print(a1)
	else:
		a2 = x * (q - 1) + y
		print(max(a2, 0))


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	k = 0
	m = int(n // x)
	k = x * m + y
	if k <= n:
		print(k)
	else:
		print(x * (m - 1) + y)


t = int(input())
while t > 0:
	(x, y, n) = map(int, input().split())
	temp = n % x
	tempo = n - temp + y
	if tempo > n:
		print(tempo - x)
	else:
		print(tempo)
	t -= 1


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	r = n % x
	if r < y:
		n -= n % x + 1
	n -= n % x - y
	print(n)


t = int(input())
for tt in range(t):
	(x, y, n) = [int(x) for x in input().split(' ')]
	r = n - y
	z = r % x
	r = r - z
	ln = round(r / x)
	print(y + r)


import math

def findK(x, y, n):
	p = math.floor((n - y) / x)
	k = p * x + y
	return k
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	print(findK(x, y, n))


t = input()
for test in range(int(t)):
	xyn_arr = [int(x) for x in input().split(' ')]
	x = xyn_arr[0]
	y = xyn_arr[1]
	n = xyn_arr[2]
	print((n - y) // x * x + y)


for i in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	a = n // x
	if a * x + y > n:
		a = a - 1
	ans = a * x + y
	print(ans)


import math
for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	if y == 0:
		print(n // x * x)
	elif n % x == 0:
		print(n - (x - y))
	elif n % x < y:
		print((n // x - 1) * x + y)
	else:
		print(n - (n % x - y))


t = int(input())
for i in range(t):
	u = input().split(' ')
	(x, y, n) = [int(i) for i in u]
	if n % x >= y:
		print(int(n / x) * x + y)
	else:
		c = int(n / x)
		if c == 0:
			print(0)
		else:
			print(int((c - 1) * x + y))


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	t = n // x
	z = n - t * x
	if y <= z:
		print(t * x + y)
	elif t != 0:
		print((t - 1) * x + y)
	else:
		print(y)


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		(x, y, n) = map(int, input().split())
		print((n - y) // x * x + y)
main()


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(X, Y, N) = map(int, input().split())
		d = N // X * X + Y
		if d > N:
			d -= X
		print(d)
main()


def game(x, y, n):
	t = n // x
	if t * x + y > n:
		return (t - 1) * x + y
	return t * x + y
t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	print(game(x, y, n))
	t = t - 1


def main(n, x, y):
	if n % x == y:
		return n
	else:
		remainder = n % x
		if remainder > y:
			return n - (remainder - y)
		else:
			di = remainder + (x - y)
			if n - di >= 0:
				return n - di
			else:
				return y
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	ans = main(n, x, y)
	print(ans)


t = int(input())
for T in range(t):
	(x, y, n) = tuple(map(int, input().split()))
	while n % x != y:
		if n % x == 0:
			n = n - (x - y)
		elif n % x < y:
			n = n - n % x
		else:
			n = n - (n % x - y)
	print(n)


ntest = int(input())
for testcase in range(ntest):
	(x, y, n) = map(int, input().split())
	t = (n - y) // x * x + y
	print(t)


t = int(input())
while t != 0:
	(a, b, c) = map(int, input().split(' '))
	x = c % a
	if x < b:
		y = abs(a - b) + x
		print(c - y)
	else:
		y = x - b
		print(c - y)
	t = t - 1


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	maxe = 0
	if n % x == y:
		print(n)
	else:
		a = n % x
		c = n - a
		if y == 0:
			print(c)
		elif a > y:
			print(n - (a - y))
		else:
			print(c - (x - y))


from math import *
from copy import *
from heapq import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from decimal import Decimal
from collections import Counter
from collections import defaultdict

def solve(l):
	(x, y, n) = l
	if n % x == y:
		return n
	if n % x > y:
		return n - (n % x - y)
	else:
		diff = y - n % x
		return n - x + diff
T = int(input())
for _ in range(T):
	l = list(map(int, stdin.readline().rstrip().split()))
	print(solve(l))


try:
	t = int(input())
	for j in range(t):
		p = list(map(int, input().rstrip().split()))
		(x, y, n) = (p[0], p[1], p[2])
		r = n % x
		if r > y:
			n = n - r + y
		elif r < y:
			n = n - (x - y + r)
		print(n)
except:
	pass


def solve():
	(x, y, n) = (int(i) for i in input().split(' '))
	k = int((n - y) / x) * x + y
	print(k)
t = int(input())
for _ in range(t):
	solve()


def solveMax(x, y, n):
	dif = x - y
	res = n % x
	if res < y:
		return n - dif - res
	else:
		return n - (res - y)
t = int(input())
for i in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	print(solveMax(x, y, n))


t = int(input().split()[0])
for i in range(t):
	(x, y, n) = map(int, input().split())
	rest = n - y
	m = rest // x
	res = y + m * x
	print(res)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		(x, y, n) = MI()
		ans = (n - y) // x * x + y
		print(ans)
main()


subtests = int(input())
for subtest in range(subtests):
	(x, y, n) = map(int, input().split())
	mod = n % x
	if mod < y:
		mod = mod + x - y
		print(n - mod)
	else:
		print(n - mod + y)


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def get_num_2_5(n):
	twos = 0
	fives = 0
	while n > 0 and n % 2 == 0:
		n //= 2
		twos += 1
	while n > 0 and n % 5 == 0:
		n //= 5
		fives += 1
	return (twos, fives)

def solution(x, y, n):
	m = n // x * x
	if m + y <= n:
		return m + y
	return (n // x - 1) * x + y

def main():
	T = 1
	T = ri()
	for i in range(T):
		(x, y, n) = ria()
		x = solution(x, y, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import math
import os
import random
import re
import sys
from collections import defaultdict
case = int(input())
for i in range(case):
	a = [int(x) for x in input().split()]
	(x, y, n) = (a[0], a[1], a[2])
	tmp = (n - y) // x
	print(x * tmp + y)


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	a = x * int(n / x) + y
	while a > n:
		a = x * (int(n / x) - 1) + y
	print(a)


t = int(input())
for i in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	m = n % x
	h = int(n - m + y)
	l = int(n - m - (x - y))
	if h > n:
		print(l)
	else:
		print(h)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	k = (n - y) // x
	print(k * x + y)


t = int(input())
for q in range(0, t):
	a = list(map(int, input().split()))
	ans = 0
	l = 0
	r = a[2]
	while r - l > 1:
		m = (r + l) // 2
		if a[0] * m + a[1] <= a[2]:
			l = m
		else:
			r = m
	print(a[0] * l + a[1])


t = int(input())
while t > 0:
	t = t - 1
	(x, y, n) = map(int, input().split())
	z = int(n / x)
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		print(n - (r - y))
	else:
		print((z - 1) * x + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	temp = n // x
	if temp * x + y > n:
		print((temp - 1) * x + y)
	elif temp * x + y == n:
		print(n)
	elif temp * x + y < n:
		print(temp * x + y)
	else:
		print(0)


def test(x, y, n):
	k1 = n // x
	r1 = n % x
	k2 = y // x
	r2 = y % x
	if r1 >= r2:
		return k1 * x + r2
	if r1 < r2:
		return k1 * x + r2 - x
t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	print(test(x, y, n))


import math

def BuubleSort(a, b, k):
	c = k % a
	if c == b:
		return k
	elif c > b:
		return k - (c - b)
	else:
		return k - c - (a - b)

def main():
	n = int(input())
	for _ in range(n):
		(a, b, k) = map(int, input().split())
		ans = BuubleSort(a, b, k)
		print(ans)
main()


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	ans1 = n // x * x + y
	if ans1 <= n:
		print(ans1)
	else:
		ans2 = (n // x - 1) * x + y
		print(ans2)


t = int(input())
for i in range(t):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	k = n
	while int(k % x) != y:
		r = int(k % x)
		if y == 0:
			m = r
		elif y > r:
			m = r + abs(x - y)
		else:
			m = r - y
		k = k - m
	print(k)


tc = int(input())
for _ in range(tc):
	(x, y, n) = list(map(int, input().split()))
	a = n % x
	if a == y:
		print(n)
	elif a > y:
		print(n - (a - y))
	else:
		print(n - x + (y - a))


for _ in range(int(input())):
	(x, y, n) = map(int, input().strip().split())
	ans = 0
	z1 = n % x
	if z1 == y:
		print(n)
	elif z1 > y:
		print(n - (z1 - y))
	else:
		a = n // x - 1
		print(a * x + y)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = n // x * x + y
	if ans > n:
		ans -= x
	print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	modv = n % x
	k = -1
	if modv == y:
		k = n
	elif modv < y:
		k = max(0, n + y - x - modv)
	else:
		k = max(0, n + y - modv)
	print(k)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(x, y, N) = MAP()
	res = N // x * x
	if res + y <= N:
		print(res + y)
	else:
		print(res - x + y)


test_case = int(input())
for i in range(test_case):
	rem = 0
	values = list(map(int, input().split(' ')))
	rem = (values[2] - values[1]) % values[0]
	print(values[2] - rem)


for _ in range(int(input())):
	(xVal, yVal, n) = map(int, input().split())
	divVal = n // xVal
	finVal = divVal * xVal + yVal
	if finVal > n:
		divVal -= 1
		print(divVal * xVal + yVal)
	else:
		print(divVal * xVal + yVal)


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		(x, y, n) = [int(i) for i in input().split(' ')]
		q = n // x
		if q * x + y <= n:
			print(q * x + y)
		else:
			print((q - 1) * x + y)
main()


t = int(input())
for tt in range(t):
	(x, y, n) = map(int, input().split())
	rem = n % x
	ans = n - rem
	if ans + y <= n:
		ans += y
	else:
		ans -= x - y
	print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	k = n
	while (k - y) % x != 0:
		k -= (k - y) % x
	print(k)


testcases = int(input())
while testcases != 0:
	(x, y, n) = input().split()
	(x, y, n) = (int(x), int(y), int(n))
	n_modulo = n % x
	n_factor = n / x
	if n - n_modulo + y <= n:
		print(n - n_modulo + y)
	elif n - n_modulo - (x - y) > 0:
		print(n - n_modulo - (x - y))
	else:
		print(0)
	testcases = testcases - 1


a = int(input())
for i in range(a):
	k = input().split()
	x = int(k[0])
	y = int(k[1])
	n = int(k[2])
	ans = n - n % x + y
	if n % x >= y:
		print(ans)
	else:
		ans -= x
		print(ans)


def func(xyn):
	(x, y, n) = list(map(int, xyn.split()))
	q = n // x
	result = x * q + y
	if result > n:
		return result - x
	return result

def main():
	for i in list(map(func, [input() for i in range(int(input()))])):
		print(i)
main()


import sys
t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, sys.stdin.readline().split()))
	temp = n // x
	val = temp * x
	ans = val + y
	if ans > n:
		ans = ans - x
	print(ans)


def required_reminder(x, y, n):
	initial_reminder = n % x - y
	if initial_reminder < 0:
		initial_reminder = x + initial_reminder
	return n - initial_reminder
test_cases = int(input())
while test_cases:
	(x, y, n) = map(int, input().split())
	print(required_reminder(x, y, n))
	test_cases -= 1


def Hello(a, b, c):
	k = c % a
	if k == b:
		return c
	elif k > b:
		c -= k - b
		return c
	else:
		c -= k
		c -= a - b
		return c
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	print(Hello(a, b, c))


t = int(input())
for i in range(0, t, 1):
	(x, y, n) = map(int, input().split())
	s = int((n - y) / x)
	sum = s * x + y
	print(sum)


t = int(input())
c = []
for i in range(t):
	(x, y, n) = input().split()
	(x, y, n) = (int(x), int(y), int(n))
	ans = n - n % x
	ans += y
	if ans > n:
		ans -= x
	c.append(ans)
for k in c:
	print(k)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		(a, b, c) = LI()
		x = c // a
		y = x * a + b
		while True:
			if y > c:
				y -= a
			else:
				break
		ans.append(y)
	for x in ans:
		print(x)
main()


def main():
	(a, y, n) = map(int, input().split())
	temp = n // a
	ans = temp * a + y
	if ans > n:
		ans = ans - a
	print(ans)

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(x, y, n) = map(int, sys.stdin.readline().split())
	ans = n // x * x + y
	while ans > n:
		ans -= x
	print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	tp = n // x
	tp = tp * x
	if tp + y > n:
		res = tp - (x - y)
	else:
		res = tp + y
	print(res)


import sys
import math
from collections import defaultdict

def solve(test):
	(x, y, n) = map(int, input().split())
	q = n // x * x
	res = q + y
	if res > n:
		res -= x
	print(res)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


def sol1():
	for t in range(int(input())):
		(x, y, n) = map(int, input().split())
		p = n // x
		k = p * x + y
		while k > n:
			p -= 1
			k = p * x + y
		print(k)
sol1()


def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = input().split()
		x = int(x)
		y = int(y)
		n = int(n)
		if x == 0:
			print('0')
		else:
			s = n // x
			if s * x + y <= n:
				print(s * x + y)
			else:
				print((s - 1) * x + y)
main()


def rem(x, y, n):
	rem = n % x
	ans = n - rem + y
	if ans > n:
		ans = ans - x
	return ans
t = int(input())
for case in range(t):
	(x, y, n) = map(int, input().split())
	print(rem(x, y, n))


t = int(input())
for i in range(t):
	a = input().split()
	a = list(map(lambda x: int(x), a))
	if a[2] % a[0] == a[1]:
		print(a[2])
	else:
		x = a[2] % a[0]
		if x > a[1]:
			a[2] = a[2] - (x - a[1])
		else:
			a[2] = a[2] + (a[1] - x) - a[0]
		if a[2] > 0:
			print(a[2])
		else:
			print(0)


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split(' ')))
	z = (n - y) % x
	n -= z
	print(n)


import math
t = int(input())
for x in range(t):
	xyn = list(map(int, input().split()))
	a = math.floor((xyn[2] - xyn[1]) / xyn[0])
	print(a * xyn[0] + xyn[1])


import sys

def input():
	return sys.stdin.readline()

def print(x):
	sys.stdout.write('\n'.join(ans))
ans = []
t = int(input())
for _ in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	p = (n - y) // x
	p = p * x + y
	ans.append(str(p))
print(ans)


n = int(input())
num = []
for _ in range(n):
	s = [int(i) for i in input().split()]
	num.append(s)
for i in range(len(num)):
	inp = num[i]
	x = inp[0]
	y = inp[1]
	k = inp[2]
	rem = k % x
	if y == 0:
		print(k - rem)
	elif y == rem:
		print(k)
	elif y < rem:
		print(k - (rem - y))
	else:
		q = k // x
		res = (q - 1) * x + y
		print(res)


t = int(input())
for p in range(0, t):
	(x, y, n) = map(int, input().split())
	d = (n - y) // x
	ans = x * d + y
	print(ans)


from math import floor as gif
t = int(input())
for i in range(t):
	string1 = input('')
	array = list(string1.split(' '))
	x = int(array[0])
	y = int(array[1])
	n = int(array[2])
	k = gif(n / x)
	a = k * x + y
	if a <= n:
		print(a)
	else:
		print(a - x)


n = int(input())
A = []
for i in range(n):
	num = input()
	num = num.split(' ')
	n = int(num[2])
	x = int(num[0])
	y = int(num[1])
	r = (n - y) % x
	A.append(n - r)
for i in A:
	print(i)


def getAns(x, y, n):
	a = (n - y) // x
	return a * x + y

def main():
	t = int(input())
	anss = [0] * t
	for i in range(t):
		(x, y, n) = map(int, input().split())
		anss[i] = getAns(x, y, n)
	for ans in anss:
		print(ans)
main()


for t in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	q = n // x
	ans = q * x
	if ans + y > n:
		ans = (q - 1) * x + y
	else:
		ans = q * x + y
	print(ans)


t = int(input())
for x in range(t):
	(x, y, n) = map(int, input().split())
	if n % x >= y:
		k = n - (n % x - y)
	else:
		k = n // x - 1
		if k < 0:
			k = 0
		k = k * x + y
	print(k)


test = int(input())
for tes in range(test):
	xyn = list(map(int, input().strip().split(' ')))
	x = xyn[0]
	y = xyn[1]
	n = xyn[2]
	rem = n % x
	lanahai = y
	if rem >= lanahai:
		ans = n - (rem - lanahai)
	else:
		t = lanahai - rem
		f = x - t
		ans = n - f
	print(ans)


queries = int(input())
for i in range(queries):
	(x, y, n) = [int(i) for i in input().split()]
	p = (n - y) // x
	k = x * p + y
	print(k)


test = int(input())
for _ in range(test):
	(x, y, n) = map(int, input().split())
	p = n // x
	d = n - p * x
	if d < y:
		p -= 1
		p *= x
		p += y
	else:
		p *= x
		p += y
	print(p)


i = int(input())
for j in range(i):
	(x, y, n) = input().split()
	(x, y, n) = (int(x), int(y), int(n))
	u = n - n % x + y
	if u <= n:
		print(u)
	else:
		print(u - x)


for i in range(int(input())):
	(a, b, n) = map(int, input().split())
	f1 = (n - b) // a
	print(f1 * a + b)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(x, y, n) = invr()
	a = (n - y) // x
	res = a * x + y
	print(res)


def rem(test):
	(x, y, n) = map(int, input().split())
	num = n // x
	space = num * x + y
	while space > n:
		space = (num - 1) * x + y
	return space
t = int(input())
l = []
for i in range(t):
	res = rem(i)
	l.append(res)
for i in l:
	print(i)


for p in range(int(input())):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	if y <= n % x:
		print(n // x * x + y)
	else:
		print(n // x * x - x + y)


t = int(input())

def de(a, b, k):
	s = (k - b) // a
	s = s * a + b
	print(s)
for i in range(t):
	(a, b, k) = map(int, input().split())
	de(a, b, k)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	(x, y, n) = listIn()
	m = n % x
	if m >= y:
		ans = n - (m - y)
	else:
		ans = n - m - (x - y)
	print(ans)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	highest = x * (n // x) + y
	sechighest = x * (n // x - 1) + y
	if highest <= n:
		print(highest)
	else:
		print(sechighest)


import math
t = int(input())
for i in range(t):
	(y, x, n) = list(map(int, input().split()))
	temp = n // y
	if y * temp + x <= n:
		print(y * temp + x)
	else:
		print(y * (temp - 1) + x)


s = int(input())
for _ in range(s):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
		continue
	a = n // x
	if a * x + y > n:
		cal = (a - 1) * x + y
	else:
		cal = a * x + y
	if cal >= 0 and cal <= n:
		print(cal)
	else:
		print(0)


t = int(input())
a = [0] * t
for i in range(t):
	s = input().split(' ')
	(x, y, n) = (int(s[0]), int(s[1]), int(s[2]))
	k = n // x * x + y
	if k > n:
		k -= x
	a[i] = k
for i in range(t):
	print(a[i])


import math
import sys
import collections
from collections import defaultdict
from sys import stdin, stdout
MOD = 10 ** 9 + 7

def take_root(num):
	return math.ceil(math.sqrt(num))

def sieve():
	limit = 86028121
	isprime = [1] * 86028122
	isprime[0] = 0
	isprime[1] = 0
	for i in range(2, take_root(limit + 1)):
		if isprime[i] == 1:
			for j in range(i * i, limit + 1, i):
				isprime[j] = 0
	primes = []
	for i in range(limit + 1):
		if isprime[i] == True:
			primes.append(i)
	return primes

def minput():
	return map(int, input().split())

def iinput():
	return int(input())

def strinput():
	return input()

def linput():
	return list(map(int, input().split()))
for _ in range(iinput()):
	(x, y, n) = minput()
	temp = n // x
	ans = temp * x + y
	if ans <= n:
		print(ans)
	else:
		print((temp - 1) * x + y)


def ints():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(x, y, n) = ints()
	p = n // x
	p = p * x
	if p + y > n:
		print(p + y - x)
	else:
		print(p + y)


t = int(input())
for i in range(t):
	(x, y, z) = list(map(int, input().split()))
	remainder = z % x
	if remainder >= y:
		k = z - (remainder - y)
	else:
		k = z - remainder - x + y
	print(k)


def solve():
	(x, y, n) = list(map(int, input().split()))
	q = n // x
	for i in range(q * x, -1, -x):
		if i % x == y:
			return i
		elif i + y <= n and (i + y) % x == y:
			return i + y

def main():
	t = int(input())
	while t:
		print(solve())
		t -= 1
main()


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	(x, y, n) = mi()
	na = n - n % x
	na += y
	while na > n:
		na -= x
	print(na)


t = int(input())
for i in range(t):
	a = input()
	arr = [int(x) for x in a.split()]
	ans = arr[-1] % arr[0]
	if ans == arr[1]:
		print(arr[-1])
	elif ans < arr[1]:
		b = arr[-1] - ans - arr[0]
		print(b + arr[1])
	elif ans > arr[1]:
		print(arr[-1] - ans + arr[1])


t = int(input())
input_index = 0
while input_index < t:
	text = str(input())
	text_index = 0
	extracted_number = text.split()
	x = int(extracted_number[0])
	y = int(extracted_number[1])
	n = int(extracted_number[2])
	if y == n % x:
		k = n
		print(k)
	elif y > n % x:
		k = int(n / x - 1) * x + y
		print(k)
	else:
		k = int(n / x) * x + y
		print(k)
	input_index = input_index + 1


def solve():
	t = int(input())
	for i in range(t):
		(x, y, n) = [int(s) for s in input().split()]
		ans = 0
		ost = n % x
		if ost >= y:
			ans = n - (ost - y)
		else:
			ans = n - x + (y - ost)
		print(ans)
solve()


t = int(input())
while t > 0:
	mylist = list(map(int, input().split()))
	x = mylist[0]
	y = mylist[1]
	n = mylist[2]
	k1 = int(n / x)
	k2 = k1 - 1
	if y <= n - k1 * x:
		print(k1 * x + y)
	else:
		print(k2 * x + y)
	t -= 1


t = int(input())
for i in range(t):
	(x, y, n) = [int(p) for p in input().split()]
	if n % x >= y:
		result = int(n / x) * x + y
		print(result)
	elif n <= x:
		print(y)
	else:
		result = (int(n / x) - 1) * x + y
		print(result)


def RequiredRemainder(x, y, n):
	sol = x * int(n / x) + y
	if sol <= n:
		return sol
	else:
		return sol - x
Lista = []
total = int(input())
for i in range(total):
	All = [int(i) for i in input().split()]
	Lista.append(All)
for j in Lista:
	print(RequiredRemainder(j[0], j[1], j[2]))


t = int(input())
for k in range(t):
	(a, b, c) = map(int, input().split())
	print(int((c - b) / a) * a + b)


from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	mxmult = n // x * x
	if mxmult + y <= n:
		print(mxmult + y)
	else:
		print((n // x - 1) * x + y)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	d1 = n // x
	while True:
		k = d1 * x + y
		if k <= n:
			print(k)
			break
		d1 = d1 - 1


T = int(input())
for _ in range(T):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	if y > n % x:
		print(n - n % x - (x - y))
	else:
		print(n - n % x + y)


a = int(input())
i = 0
while a > i:
	b = input().split()
	x = int(b[0])
	y = int(b[1])
	n = int(b[2])
	v = n // x
	if v * x + y > n:
		print((v - 1) * x + y)
	else:
		print(v * x + y)
	i += 1


t = int(input())
for _t in range(t):
	(x, y, n) = map(int, input().split())
	r = n // x
	m = r * x
	if m + y <= n:
		print(m + y)
	else:
		print(m + y - x)


for ii in range(int(input())):
	(x, y, n) = map(int, input().split())
	val = n // x * x + y
	if val <= n:
		print(val)
	else:
		print(val - x)


cases = int(input())
for i in range(cases):
	line1 = input().split(' ')
	x = int(line1[0])
	y = int(line1[1])
	n = int(line1[2])
	check = n % x
	if y == check:
		print(n)
	elif y < check:
		print(n - (check - y))
	elif y > check:
		diff = x - y
		ans = n - check - diff
		print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	z = int(n // x)
	if z * x + y > n:
		z -= 1
		ans = z * x + y
	else:
		ans = z * x + y
	print(ans)


from sys import stdin, stdout
input = stdin.readline

def solve(cs):
	(x, y, k) = map(int, input().split())
	m = k % x
	if m >= y:
		print(k - (m - y))
	else:
		print(k - m - (x - y))
for tc in range(int(input())):
	solve(tc + 1)


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	d = n // x
	r = n % x
	if n < x:
		print(y)
	else:
		if r > y:
			print(n - r + y)
		if r == y:
			print(d * x + y)
		if r < y:
			print((d - 1) * x + y)
	t = t - 1


T = int(input().strip())
for t in range(T):
	(x, y, n) = list(map(int, input().strip().split()))
	k = n - n % x + y
	if k > n:
		k -= x
	print(k)


for _ in range(int(input())):
	(m, n, p) = list(map(int, input().split()))
	store = p // m
	kept = p % m
	if kept == n:
		print(p)
	elif kept < n:
		pp = m * (p // m) - (m - n)
		print(pp)
	else:
		print(m * (p // m) + n)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	z = n // x
	while x * z + y > n:
		z -= 1
	print(x * z + y)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a == y:
		print(n)
	elif a == 0:
		print(n - x + y)
	elif a > y:
		print(n - a + y)
	else:
		print(n - (x + a) + y)


def f(x, y, n):
	y_1 = n % x
	if y_1 >= y:
		return n - (y_1 - y)
	else:
		return n - y_1 - (x - y)

def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = tuple(map(int, input().split()))
		print(f(x, y, n))
main()


t = int(input())
for i in range(t):
	(x, y, n) = [int(h) for h in input().split()]
	a = n - n % x + y
	b = n - n % x - (x - y)
	if a > n:
		print(b)
	else:
		print(a)


a = int(input())
for i in range(a):
	(b, c, d) = map(int, input().split())
	e = d // b
	while d - e * b < c:
		e = e - 1
	print(b * e + c)


t = int(input())
for z in range(t):
	(x, y, n) = map(int, input().strip().split())
	d = int(n // x)
	rem = n % x
	e = d * x
	if e + y <= n:
		ans = e + y
	else:
		f = (d - 1) * x
		ans = f + y
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if c % a < b:
		d = c // a - 1
		print(d * a + b)
	else:
		d = c // a
		print(d * a + b)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	temp = 0
	temp = z // x
	while True:
		if temp * x + y <= z:
			print(temp * x + y)
			break
		temp -= 1


import math

def nod(a, b):
	while True:
		if a > b:
			if a % b == 0:
				return b
				break
			else:
				a = a % b
		elif b % a == 0:
			return a
			break
		else:
			b = b % a

def dtod(a):
	s = ''
	while a != 0:
		s += str(a % 2)
		a = int(a / 2)
	return s[::-1]

def _8_(a):
	return a[0] * a[1] * a[2] * a[3] * a[4] * a[5] * a[6] * a[7] * a[8] * a[9]
t = int(input())
for i in range(t):
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	c = int(s[2])
	z = c % a
	x = (c - z) / a
	if int(a * x + b) <= c:
		print(int(a * x + b))
	else:
		print(int(a * (x - 1) + b))


tests = int(input())
for _ in range(tests):
	(x, r2, n) = map(int, input().split())
	r1 = n % x
	res = 0
	if r1 > r2:
		res = n - (r1 - r2)
	elif r1 < r2:
		res = n + (r2 - r1) - x
	else:
		res = n
	print(res)


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split(' ')))
	a = n % x
	b = abs(a - y)
	if n % x == y:
		print(n)
	elif a > y:
		print(n - a + y)
	else:
		print(n - a - x + y)


n = int(input())
alist = []
for i in range(n):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a < y:
		b = a + x - y
		n = n - b
		alist.append(n)
	elif a > y:
		b = a - y
		n = n - b
		alist.append(n)
	elif a == y:
		alist.append(n)
for i in alist:
	print(i)


def go(x, y, k):
	n = k % x
	if n == y:
		return k
	else:
		return k + (y - n) if k + (y - n) <= k else k + (y - n) - x
t = int(input())
for i in range(t):
	(x, y, k) = list(map(int, input().split()))
	print(go(x, y, k))


t = int(input())
import math
for _ in range(t):
	(x, y, n) = list(map(int, input().rstrip().split()))
	if y == 0:
		print(int(n // x) * x)
		continue
	else:
		rem = n % x
		if rem == y:
			print(n)
			continue
		elif rem > y:
			print(n - (rem - y))
		else:
			rem = rem + x - y
			print(n - rem)


t = int(input())
for i in range(t):
	(x, y, n) = input().split()
	a = int(x)
	b = int(y)
	c = int(n)
	r = int(c / a)
	if c % a == b:
		print(c)
	if c % a < b:
		print(a * r - a + b)
	if c % a > b:
		print(a * r + b)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def printp(p):
	for i in p:
		print(i)
MOD = 10 ** 9 + 7
T = 1
T = int(stdin.readline())
for _ in range(T):
	(x, y, n) = list(map(int, stdin.readline().split()))
	q = n // x
	if q * x + y <= n:
		print(q * x + y)
	else:
		print((q - 1) * x + y)


for _ in range(int(input())):
	(x, y, k) = map(int, input().split())
	if k % x == y:
		print(k)
	else:
		t = k % x
		if t < y:
			k = k - t
			if k % x == y:
				print(k)
			else:
				k = k - abs(x - y)
				print(k)
		else:
			t = k // x
			print(t * x + y)


t = int(input())
for tit in range(t):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	i = (n - y) // x
	k = y + i * x
	print(k)


def ans(a, b, c):
	if c % a == b:
		print(c)
	else:
		m = c % a
		if m > b:
			print(c - (m - b))
		else:
			c = c - (m + a)
			print(c + b)
t = int(input())
while t > 0:
	(a, b, c) = map(int, input().split())
	ans(a, b, c)
	t -= 1


t = int(input())
for _ in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	a = n // x * x
	if a + y <= n:
		print(a + y)
	else:
		print(a + y - x)


from math import *
tests = int(input())
for t in range(tests):
	(x, y, n) = map(int, input().split())
	d = (n - y) // x
	k = d * x + y
	print(k)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())
for _ in range(ii()):
	(x, y, n) = mi()
	if n % x < y:
		print(n - n % x - x + y)
	else:
		print(n - n % x + y)


t = int(input())
while t:
	t -= 1
	(x, y, n) = [int(x) for x in input().split()]
	ans = (n - y) // x
	print(x * ans + y)


import math
from sys import *
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		print(n - (r - y))
	else:
		print(n - (r + (x - y)))


t = int(input())
while t > 0:
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	a = (n - y) // x
	a = a * x + y
	print(a)
	t -= 1


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	a += 1
	b = y + 1
	if a < b:
		c = a + (x - b)
		n = n - c
		if n < 0:
			print(0)
		else:
			print(n)
	elif a >= b:
		c = a - b
		n = n - c
		print(n)


import sys
input = sys.stdin.readline
out = sys.stdout

def main():
	q = int(input())
	for i in range(q):
		(x, y, n) = map(int, input().split())
		mod = n % x
		if mod == y:
			print(n)
		elif mod > y:
			print(n - (mod - y))
		else:
			print(n - mod - (x - y))
main()


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	rem = n % x
	quo = n // x
	if rem >= y:
		q = quo * x + y
	elif rem < y:
		q = (quo - 1) * x + y
	print(q)


(x, y, n) = ([], [], [])
t = int(input())
for _ in range(t):
	z = list(map(int, input().strip().split()))
	x.append(z[0])
	y.append(z[1])
	n.append(z[2])
for test in range(t):
	if y[test] == 0 and x[test] > n[test]:
		print(0)
	else:
		ans = n[test] - n[test] % x[test] + y[test]
		if ans > n[test]:
			ans -= x[test]
		print(ans)


test = int(input())
for i in range(test):
	(x, y, n) = map(int, input().split())
	temp = n % x
	c = n // x
	if temp < y:
		c -= 1
	k = c * x + y
	print(k)


t = int(input())
for q in range(t):
	(x, y, n) = map(int, input().split())
	z = n % x
	if z < y:
		n = n - (z + (x - y))
	elif y < z:
		n = n - (z - y)
	print(n)


tot = int(input().strip())
while tot > 0:
	(x, y, n) = [int(x) for x in input().strip().split(' ')]
	if n % x < y:
		d = y - n % x
		ans = n - x + d
	elif n % x > y:
		ans = n - (n % x - y)
	else:
		ans = n
	print(ans)
	tot -= 1


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	if not x:
		print(0)
	elif n // x * x + y > n:
		print(n // x * x + y - x)
	else:
		print(n // x * x + y)


def reqRem(arr):
	(x, y, n) = (arr[0], arr[1], arr[2])
	q = n // x
	if q * x + y <= n:
		return q * x + y
	else:
		q -= 1
		return q * x + y
tc = int(input())
for i in range(tc):
	inp = list(map(int, input().split()))
	print(reqRem(inp))


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	k1 = n // x * x + y
	while k1 > n:
		k1 -= x
	print(k1)


t = int(input())
p = []
for i in range(t):
	u = list(map(int, input().split()))
	p.append(u)

def api(x, y, n):
	if n // x == 0:
		return y
	else:
		t = n // x
		p = t * x + y
		if p <= n:
			return p
		else:
			return (t - 1) * x + y
for i in range(t):
	r = api(p[i][0], p[i][1], p[i][2])
	print(r)


t = int(input())
for i in range(t):
	b = list(map(int, input().split()))
	(x, y, n) = (b[0], b[1], b[2])
	r = (n - y) // x
	print(r * x + y)


t = int(input())
case_lists = []
for i in range(t):
	case_lists.append((int(x) for x in input().split()))
for item in case_lists:
	(x, y, n) = item
	if n - n % x + y > n - n % x - (x - y) and n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(x, y, n) = iia()
	num = n // x
	if x * num + y > n:
		print(x * num - (x - y))
	else:
		print(x * num + y)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	aa = [LI() for _ in range(t)]
	rr = []
	for (x, y, n) in aa:
		t = n // x * x + y
		if t > n:
			t -= x
		rr.append(t)
	return JA(rr, '\n')
print(main())


def f(x, y, n):
	t1 = n // x
	t2 = t1 - 1
	t3 = t1 + 1
	if t3 * x + y >= 0 and t3 * x + y <= n:
		return t3 * x + y
	if t1 * x + y >= 0 and t1 * x + y <= n:
		return t1 * x + y
	if t2 * x + y >= 0 and t2 * x + y <= n:
		return t2 * x + y
for tc in range(int(input())):
	al = list(map(int, input().split()))
	print(f(al[0], al[1], al[2]))


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	div = n // x
	ans = div * x + y
	if ans > n:
		ans -= x
	print(ans)


t = int(input())
for i in range(t):
	l = list(map(int, input().rstrip().split()))
	k = (l[2] - l[1]) % l[0]
	res = l[2] - k
	print(res)


t = int(input())
for i in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	d = n // x
	e = d * x
	f = x - y
	if e + y > n:
		e = e - f
	else:
		e = e + y
	print(e)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	req = n - y
	rem = req % x
	print(n - rem)


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	ans = y
	mul = 0
	(lo, hi) = (1, 10 ** 9)
	while lo <= hi:
		m = (lo + hi) // 2
		if m * x + y <= n:
			mul = m
			lo = m + 1
		else:
			hi = m - 1
	print(mul * x + y)


t = int(input())
a = 0
for j in range(t):
	s = input().split()
	x = int(s[0])
	y = int(s[1])
	n = int(s[2])
	a = 0
	i = n
	if n % x == y:
		print(n)
	elif n % x > y:
		print(n - (n % x - y))
	else:
		print(n - n % x - (x - y))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = (n - y) // x
	print(y + a * x)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	r = c % a
	if c < a:
		print(b)
	elif r == b:
		print(c)
	elif c - r + b > c:
		print(c - r - (a - b))
	else:
		print(c - r + b)


for i in range(int(input())):
	(x, y, n) = map(int, input().split(' '))
	if x > n:
		print(y)
		continue
	a = n % x
	if y > a:
		n = n - a - x + y
	elif y < a:
		n = n - a + y
	print(n)


for _ in range(int(input())):
	(x, y, k) = map(int, input().split())
	if k % x == y:
		print(k)
	else:
		p = k % x
		if p > y:
			print(max(0, k - (p - y)))
		else:
			print(max(0, k - x - k % x + y))


t = int(input())
for v in range(t):
	(x, y, n) = map(int, input().split(' '))
	rem = n % x
	if rem == y:
		print(n)
	elif rem > y:
		print(n - (rem - y))
	else:
		print(n - rem - (x - y))


n_sets = int(input())
for i in range(n_sets):
	(delim, ost, _max_k) = [int(x) for x in input().split()]
	var = _max_k // delim * delim
	if var + ost <= _max_k:
		print(var + ost)
	elif var - delim + ost > 0:
		print(var - delim + ost)


x = int(input())
for _ in range(x):
	(x, y, n) = [int(num) for num in input().split(' ')]
	k = n
	if k % x == y:
		print(k)
	elif k % x > y:
		print(k - (k % x - y))
	else:
		print(k - (k % x + x - y))


t = int(input())
for q in range(0, t):
	(x, y, n) = map(int, input().split())
	m = n - y
	l = m // x
	print(x * l + y)


T = int(input())
for i in range(T):
	(x, y, n) = [int(i) for i in input().split()]
	v = n // x
	while v >= 0:
		if v * x + y <= n:
			print(v * x + y)
			break
		v -= 1


T = int(input())
for tc in range(1, T + 1):
	(x, y, n) = map(int, input().split())
	mod = n % x
	if mod > y:
		print(n - (mod - y))
	elif mod < y:
		print(n - (mod + x - y))
	else:
		print(n)


def main():
	t = int(input())
	ans = []
	for i in range(t):
		(x, y, n) = map(int, input().split())
		k = y + x * ((n - y) // x)
		ans.append(k)
	for i in ans:
		print(i)
main()


t = int(input())
while t > 0:
	t -= 1
	(x, y, n) = [int(x) for x in input().split(' ')]
	v = n - n % x
	while v + y > n:
		v -= x
	print(v + y)


t = int(input())
for x in range(t):
	(x, y, n) = map(int, input().split())
	r = n % x
	if y < r:
		m = n - (r - y)
	else:
		m = n + (y - r)
	if n < x:
		print(y)
		continue
	while True:
		if m <= n:
			print(m)
			break
		else:
			m = m - x


t = int(input())
for i in range(t):
	(x, y, k) = map(int, input().split(' '))
	a = -1
	rem = k % x
	if rem == y:
		print(k)
	elif rem > y:
		f = rem - y
		print(k - f)
	else:
		f = y - rem
		print(k - x + f)


GI = lambda : int(input())
GIS = lambda : map(int, input().split())
LGIS = lambda : list(GIS())

def main():
	for _ in range(GI()):
		(x, y, n) = GIS()
		for k in range(n // x, -1, -1):
			k *= x
			k += y
			if k <= n:
				print(k)
				break
main()


for _ in range(int(input())):
	a = [int(y) for y in input().split(' ')]
	x = a[0]
	y = a[1]
	n = a[2]
	q = n % x
	c = q - y
	if n - c > n:
		print(n - c - x)
	else:
		print(n - c)


import sys
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
for _ in range(I()):
	(x, y, n) = li()
	ans = n // x * x + y
	if ans > n:
		ans -= x
	print(ans)


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = 0
	temp = n // x
	while temp * x + y > n:
		temp -= 1
	print(temp * x + y)


t = int(input())
while t:
	t -= 1
	(x, y, n) = [i for i in map(int, input().strip().split())]
	print((n - y) // x * x + y)


from sys import stdin, stdout
input()
for i in stdin:
	(x, y, n) = map(int, i.split())
	if n % x >= y:
		stdout.write(str(n // x * x + y) + '\n')
	else:
		stdout.write(str((n // x - 1) * x + y) + '\n')


T = int(input())
for _ in range(T):
	(x, y, n) = map(int, input().split())
	r = n % x
	s = n // x
	if y <= r:
		print(s * x + y)
	else:
		print((s - 1) * x + y)


t = int(input())
for z in range(t):
	(x, y, n) = map(int, input().split())
	remainder = n % x
	if remainder == y:
		print(n)
	elif remainder < y:
		print(n - (x - abs(remainder - y)))
	else:
		print(n - abs(remainder - y))


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heappushpop, heapreplace

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['YES', 'NO']
test_case = ii()
while test_case:
	test_case -= 1
	(x, y, n) = mi()
	z = n // x * x
	z += y
	if z > n:
		z -= x
	print(z)


def call():
	(x, y, n) = map(int, input().split())
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))
for _ in range(int(input())):
	call()


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left, bisect_right
import threading
from collections import Counter, defaultdict
arr = []

def main():
	for _ in range(int(input())):
		(x, y, n) = map(int, input().split())
		(d, r) = (n // x, n % x)
		if y <= r:
			print(d * x + y)
		else:
			print((d - 1) * x + y)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	t1 = n // x
	t2 = t1 * x
	if t2 + y <= n:
		print(t2 + y)
	else:
		print(t2 - (x - y))


def A(x, y, n):
	max = n // x * x + y
	if max > n:
		max -= x
	return max
a = int(input())
for i in range(a):
	(x, y, n) = map(int, input().split())
	print(A(x, y, n))


for pavan in range(int(input())):
	(x, y, k) = map(int, input().strip().split())
	m = k % x
	if m < y:
		i = x - y
		l = k - (m + i)
		if l < 0:
			print(0)
		else:
			print(l)
	elif m == y:
		print(k)
	elif m > y:
		print(k - (m - y))


def raf(x, y, n):
	if int(n / x) * x + y <= n:
		return int(n / x) * x + y
	else:
		return int(n / x) * x - x + y
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	print(raf(x, y, n))


import sys
from math import floor as fl
cont = sys.stdin.readlines()
cont = [i.strip('\n').split() for i in cont]
numTests = int(cont.pop(0)[0])
for i in cont:
	(x, y, n) = [int(j) for j in i]
	n -= y
	n = fl(n / x)
	print(n * x + y)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	val = n // x
	ans = val * x
	if ans + y > n:
		print(ans - (x - y))
	else:
		print(ans + y)


t = int(input())
for isc in range(t):
	(x, y, n) = map(int, input().split())
	rem = n % x
	nn = n - rem + y
	if nn > n:
		print(nn - x)
	else:
		print(nn)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	m = 0
	s = int(n / x) * x
	while s + y > n:
		s -= x
	print(s + y)


L = int(input())

def rem(x, y, n):
	if n % x > y:
		k = n - abs(y - n % x)
	elif n % x < y:
		k = n + abs(y - n % x) - x
	else:
		k = n
	return k
for i in range(L):
	(x, y, n) = map(int, input().split())
	ans = rem(x, y, n)
	print(ans)


tests = int(input())
arr = []
for i in range(tests):
	nums = list(map(int, input().split()))
	arr.append(nums)
for nums in arr:
	(x, y, n) = nums
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x + y - x)


a = int(input())
for i in range(a):
	(x, y, n) = list(map(int, input().split()))
	r = n // x * x
	if r + y <= n:
		print(r + y)
	else:
		print(max(r - x + y, y))


try:
	t = int(input())
	while t:
		(a, b, n) = map(int, input().split())
		c = n % a
		d = 0
		if c == b:
			d = n
		elif b > c:
			d = n + b - c - a
		else:
			d = n - (c - b)
		print(d)
except:
	pass


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
from collections import defaultdict as df
import copy
import math
t = int(input().strip())
for _ in range(t):
	(x, y, n) = RI()
	temp = n // x * x
	if temp + y <= n:
		print(temp + y)
	else:
		print(temp - (x - y))


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	found = False
	a = x - y
	z = n % x
	if z == y:
		print(n)
	elif z < y:
		print(n - (z + a))
	elif z > y:
		print(n - (z - y))


def printModulo():
	flag = True
	(x, y, n) = map(int, input().split())
	k = n
	while flag:
		if k % x == y:
			print(k)
			flag = False
		else:
			k -= 1

def printM():
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	elif n % x < y:
		print(n - n % x + y - x)
	else:
		print(n - n % x + y)
num = int(input())
for i in range(num):
	printM()


t = int(input())
import math
for _ in range(t):
	(x, y, n) = map(int, input().split())
	q = math.floor((n - y) / x)
	ans = q * x + y
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	ans = x * ((n - y) // x) + y
	print(ans)


def solve():
	(x, y, n) = map(int, input().split())
	p = (n - y) // x
	print(p * x + y)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
parameters = [input().split(' ') for i in range(t)]
for l in parameters:
	x = int(l[0])
	y = int(l[1])
	n = int(l[2])
	mod_ = 0
	if n % x == y:
		mod_ = n
	elif x == n and y == 1:
		mod_ = 1
	else:
		m = n % x
		if y >= m:
			mod_ = n - (m + x - y)
		else:
			mod_ = n - (m - y)
	print(mod_)


for i1 in range(int(input())):
	(x, y, n) = map(int, input().split())
	temp = n // x
	ans = x * temp + y
	if ans <= n:
		print(ans)
	else:
		while ans > n:
			ans = ans - x
		print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().strip().split())
	m = n % x
	if m < y:
		i = x - y
		l = n - (m + i)
		if l < 0:
			print(0)
		else:
			print(l)
	elif m == y:
		print(n)
	elif m > y:
		print(n - (m - y))


t = int(input())
for q in range(t):
	(x, y, n) = map(int, input().split())
	c = n % x
	if y > c:
		n -= c + (x - y)
	else:
		n -= c - y
	print(n)


a = int(input())
for _ in range(a):
	(x, y, z) = map(int, input().split())
	k = z % x
	if k == y:
		print(z)
	elif k > y:
		print(z - (k - y))
	else:
		print(z - (k - y + x))


def readintlst():
	return list(map(int, input().split(' ')))

def readn():
	return int(input())
N = readn()
for _ in range(N):
	(x, y, n) = readintlst()
	t = n // x
	ans = t * x + y
	while ans > n:
		ans -= x
	print(ans)


t = int(input())
for _ in range(0, t):
	li = list(map(int, input().split(' ')))
	x = li[0]
	y = li[1]
	n = li[2]
	ans = n
	while not ans % x == y:
		val = ans % x
		if val == y:
			break
		elif y > val:
			ans = ans - (val + abs(y - x))
		else:
			ans = ans - abs(val - y)
	print(ans)


T = int(input().rstrip())

def solve(x, y, n):
	maxm = n // x
	total = maxm * x
	if total + y <= n:
		print(total + y)
		return
	print(total + y - x)
for test in range(T):
	(x, y, n) = [int(x) for x in input().split()]
	solve(x, y, n)


t = int(input())
while t:
	line = input().split()
	(x, y, n) = (int(line[0]), int(line[1]), int(line[2]))
	q = (n - y) // x
	print(q * x + y)
	t -= 1


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(x, y, n) = map(int, inputi().split())
	nm = n % x
	k = n - (nm - y) % x
	print(k)

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


t = int(input())
for i in range(t):
	[x, y, n] = list(map(int, input().split()))
	s = n // x
	r = n % x
	if r >= y:
		k = n - (r - y)
	else:
		k = (s - 1) * x + y
	print(k)


from collections import defaultdict as dfd
import math
import sys
import heapq

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def main():
	for _ in range(int(input())):
		(x, y, n) = MI()
		if n % x >= y:
			print(n // x * x + y)
		else:
			print((n // x - 1) * x + y)
main()


tc = int(input())
for i in range(tc):
	(x1, y1, n1) = map(int, input().split(' '))
	k = n1 % x1
	if k > y1:
		print(n1 - (k - y1))
	elif k == y1:
		print(n1)
	else:
		print(n1 - (x1 - (y1 - k)))


T = int(input())

def main():
	(x, y, n) = tuple(map(int, input().split()))
	m = n // x
	m = m * x
	m = m + y
	if m < 0:
		return 0
	else:
		if m <= n:
			return m
		m = m - x
		if m <= n and m > 0:
			return m
		if m <= 0:
			return 0
		else:
			while m > n:
				m = m - x
		return m
for i in range(T):
	print(main())


import sys
from math import log2, floor
TEST = 0
if TEST == 1:
	input_file = open('inputA.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))

def read_str_to_list():
	if TEST:
		in1 = input_from_file.pop(0).rstrip()
	else:
		in1 = sys.stdin.readline().rstrip()
	return [x for x in in1]
tests = read_int()
for test in range(tests):
	(x, y, n) = read_ints()
	ost = n % x
	if ost == y:
		k = n
	elif ost < y:
		k = n - ost - (x - y)
	else:
		k = n - (ost - y)
	k = max(0, k)
	print(k)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' ', end='\n'):
	print(sep.join(map(str, a)), end=end)

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
for _ in range(ii()):
	(x, y, n) = mi()
	t = n // x
	f = n - t * x < y
	print((t - f) * x + y)


n = int(input())
for _ in range(n):
	(x, y, z) = input().split()
	x = int(x)
	y = int(y)
	z = int(z)
	if z % x == y:
		print(z)
	elif z % x < y:
		m = y - z % x
		res = z + m - x
		print(max(0, res))
	else:
		m = z % x - y
		res = z - m
		print(max(0, res))


t = int(input())
from math import *
for xy in range(t):
	(x, y, n) = list(map(int, input().split()))
	tq = (n - y) // x
	print(tq * x + y)


t = int(input())
for _ in range(t):
	(a, b, num) = map(int, input().split())
	rem = num % a
	if rem > b:
		print(num - (rem - b))
	elif rem == b:
		print(num)
	else:
		print(num - (a - (b - rem)))


import sys
caseCount = int(next(sys.stdin))

def solve(x, y, n):
	div = n // x * x
	if div + y <= n:
		return div + y
	return div - x + y
for i in range(caseCount):
	case = next(sys.stdin)[:-1]
	k = case.split(' ')
	x = int(k[0])
	y = int(k[1])
	n = int(k[2])
	print(solve(x, y, n))


from sys import stdin
_input = stdin.readline
(_int, _range) = (int, range)

def solution():
	for _ in _range(_int(_input())):
		(x, y, n) = [_int(i) for i in _input().split()]
		ans = n - n % x + y
		if ans <= n:
			print(ans)
			continue
		else:
			print(n - n % x + y - x)
solution()


from __future__ import division, print_function

def get_ints():
	return map(int, input().strip().split())

def get_array():
	return list(map(int, input().strip().split()))

def main():
	for _ in range(int(input())):
		(x, y, n) = get_ints()
		difval = n - y
		val = difval // x * x
		print(val + y)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(x, y, n) = inputnums()
	ans = (n - y) // x * x + y
	print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	v = n % x
	if v >= y:
		diff = v - y
		n = n - diff
		print(n)
	else:
		n = n - v
		diff = x - y
		n = n - diff
		print(n)


I = input
import math
for _ in range(int(I())):
	(x, y, z) = map(int, I().split())
	t = z // x
	t *= x
	ans = t - (x - y) if t + y > z else t + y
	print(ans)


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	(x, y, n) = idata()
	d = x * (n // x) + y
	d -= x if d > n else 0
	print(d)
	return
for t in range(int(ii())):
	solve()


def f(x, y, n):
	return (n - y) // x * x + y
q = int(input())
for _ in range(q):
	print(f(*tuple(map(int, input().split()))))


t = int(input())
for _ in range(t):
	(x, y, n) = list(map(int, input().split()))
	p = n % x
	eroor = y - p
	if eroor > 0:
		print(n - (x - eroor))
	else:
		print(n + eroor)


t = int(input())
while t:
	a = list(map(int, input().split()))
	x = a[0]
	y = a[1]
	n = a[2]
	m = n
	r = n % x
	n = n - r
	if n + y <= m:
		print(n + y)
	else:
		n = n - x
		print(n + y)
	t = t - 1


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	rem = n // x
	mod = n % x
	if mod >= y:
		pass
	else:
		rem -= 1
	i = rem * x + y
	print(i)


from collections import deque
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left as bl
from math import log2, ceil
from itertools import permutations

def main():
	for t in range(int(input())):
		(x, y, n) = [int(j) for j in input().split()]
		a = n // x
		if a * x + y <= n:
			print(a * x + y)
		else:
			print((a - 1) * x + y)
main()


import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		(x, y, n) = ain()
		p = n // x
		j = p - 1
		if p * x + y <= n:
			print(p * x + y)
		else:
			print(j * x + y)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().rstrip().split()))
	res = n % x
	if res == y:
		print(n)
	elif res < y:
		print(n - (res + x - y))
	elif res > y:
		print(n - (res - y))


n = int(input())
for x in range(n):
	A = list(map(int, input().split()))
	(x, y, n1) = (A[0], A[1], A[2])
	ans = n1 - n1 % x + y
	if ans > n1:
		print(ans - x)
	else:
		print(ans)


t = int(input())
for case in range(t):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	elif n % x > y:
		print(n - (n % x - y))
	else:
		print(n // x * x - x + y)


for _ in range(int(input())):
	e = t = 0
	(x, y, n) = map(int, input().split())
	e = n // x
	e = e * x + y
	if e > n:
		print(e - x)
	else:
		print(e)


t = int(input())
for i in range(t):
	(x, y, n) = tuple(map(int, input().split()))
	rem = n % x
	if rem == y:
		print(n)
	elif rem < y:
		new_n = n - rem
		print(new_n - (x - y))
	elif (rem > y) & (n > x):
		print(n - (rem - y))
	elif n < x:
		print(y)


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	r = n % a
	if r >= b:
		print(n - r + b)
	elif r < b:
		print(n - r - a + b)


from math import log

def solve():
	(x, y, n) = map(int, input().split())
	ans = n // x * x + y
	print(ans if ans <= n else ans - x)
t = int(input())
for _ in range(t):
	solve()


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def primes(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def solve():
	(x, y, n) = [int(x) for x in input().split()]
	ans = n // x * x + y
	if ans > n:
		ans -= x
	print(ans)
tt = int(input())
for test in range(tt):
	solve()


t = int(input())
for r in range(t):
	(x, y, n) = list(map(int, input().split()))
	c = 0
	if n % x == y:
		c = n
	elif x == n:
		c = y
	elif n % x < y:
		c = n - n % x - (x - y)
	elif n % x > y:
		c = n - (n % x - y)
	print(c)


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	j = (n - y) // x
	k = x * j + y
	print(k)


t = int(input())
for _ in range(t):
	(x, y, n) = [int(s) for s in input().split()]
	if n // x * x + y > n:
		print((n // x - 1) * x + y)
	else:
		print(n // x * x + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	ans = n // x
	res = ans * x + y
	while res > n:
		res = res - x
	print(res)


import sys
input = sys.stdin.readline

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()

def lower_letters():
	lowercase = [chr(i) for i in range(97, 97 + 26)]
	return lowercase

def how_frequent(lis):
	last = None
	count = []
	each = 1
	for i in range(len(lis)):
		if last != None:
			last = lis[i - 1]
		if last == lis[i]:
			each += 1
		else:
			count.append(each)
			each = 0
		last = lis[i]
	return max(count)

def upper_letters():
	uppercase = [chr(i) for i in range(65, 65 + 26)]
	return uppercase
for _ in range(int(input())):
	(x, y, n) = int_array()
	now = n % x
	if now >= y:
		ans = n - (now - y)
	else:
		zero = n - now
		ans = zero - (x - y)
	print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	xy = x * y
	ndivx = n // x
	abc = ndivx * x + y
	if abc <= n:
		print(abc)
	else:
		abc = (ndivx - 1) * x + y
		print(abc)


t = int(input())
for case in range(t):
	(x, y, n) = list(map(int, input().split()))
	md = n % x
	if md >= y:
		n -= md - y
	else:
		n -= x
		n += y - md
	print(n)


tl = input()
for t in range(int(tl)):
	(x, y, n) = map(int, input().split(' '))
	k = y
	while True:
		if k + x > n:
			break
		m = x
		while True:
			if k + m > n:
				break
			k += m
			m <<= 1
	print(k)


times = int(input())
for i in range(times):
	val = list(map(int, input().split(' ')))
	x = val[2] - val[1]
	z = int(x / val[0])
	k = z * val[0] + val[1]
	print(k)


import math
t = int(input())
for i in range(t):
	flag = 0
	(x, y, n) = map(int, input().split())
	z = n - y
	z = z // x
	z = x * z + y
	print(z)


import sys
input = sys.stdin.readline
for T in range(int(input())):
	(x, y, a) = list(map(int, input().split()))
	k = a % x
	d = y - k
	if d <= 0:
		print(a - abs(d))
	else:
		a -= abs(k)
		a -= x
		print(a + y)


for i in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	count = 0
	while n >= 0:
		rem = n % x
		if rem == y:
			print(n)
			break
		elif rem > y:
			print(n - (rem - y))
			break
		elif rem < y:
			print(n + (y - rem) - x)
			break


import sys, math, cmath, time
start_time = time.time()

def solve():
	(x, y, n) = invr()
	print(min(n, (n - y) // x * x) + y)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = (q[ord(a[i]) - 97], 1)
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	k = n % x
	if k == y:
		print(n)
	if y > k:
		a1 = n - x - k + y
		if a1 < 0:
			print(0)
		else:
			print(a1)
	if y < k:
		a2 = n - k + y
		if a2 < 0:
			print(0)
		else:
			print(a2)


def solve():
	[x, y, n] = [int(x) for x in input().split()]
	if n % x == y:
		return n
	z = x
	s = n // x
	x *= s
	if x + y > n:
		return x + y - z
	return x + y

def main():
	n = int(input())
	while n > 0:
		ans = solve()
		print(ans)
		n -= 1
main()


def find(x, y, n):
	z = (n - y) // x
	return z * x + y
for _ in range(int(input())):
	(x, y, n) = list(map(int, input().strip().split()))
	print(find(x, y, n))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	rem = k % n
	if rem >= m:
		print(k - rem + m)
	else:
		d = m - rem
		tmp = k // n - 1
		ans = tmp * n + m
		print(ans)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	en = n // x * x + y
	st = (n // x - 1) * x + y
	if st <= n and en <= n:
		print(max(st, en))
	elif st <= n and en > n:
		print(st)


test_cases = int(input())
for k in range(test_cases):
	(x, y, n) = [int(i) for i in input().split(' ')]
	b = n % x
	if b == y:
		print(n)
	elif b > y:
		print(n - b + y)
	else:
		print(n - b - (x - y))


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	ans1 = n % x
	ans2 = x - y
	ans3 = (ans1 + ans2) % x
	print(n - ans3)


t = int(input())
for x in range(t):
	(x, y, n) = list(map(int, input().split()))
	chk = n % x
	if chk == y:
		print(n)
		continue
	if chk < y:
		n -= n % x
		n -= x - y
		print(n)
		continue
	if chk > y:
		n -= n % x - y
		print(n)
		continue


import math
import collections
import sys

def inpu():
	return input().split(' ')

def inti(a):
	for i in range(len(a)):
		a[i] = int(a[i])
	return a

def inp():
	a = inpu()
	a = inti(a)
	return a
for _ in range(int(input())):
	a = inp()
	(x, y, n) = (a[0], a[1], a[2])
	if n % x > y:
		n = n - (n % x - y)
	elif n % x < y:
		n = n - n % x - x + y
	print(n)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	(x, y, n) = map(int, input().split())
	mul = (n - y) // x
	ans = mul * x + y
	print(ans)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	temp = n // x
	k = temp * x + y
	if k > n:
		print(k - x)
	else:
		print(k)


def f():
	(x, y, n) = map(int, input().split())
	k = n // x
	ans = x * k + y
	if ans > n:
		print(x * (k - 1) + y)
	else:
		print(ans)
t = int(input())
for i in range(t):
	f()


import sys
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	(x, y, n) = map(int, input().split())
	ans = 0
	if n // x == 0:
		ans = y
	elif n // x * x + y <= n:
		ans = n // x * x + y
	else:
		ans = (n // x - 1) * x + y
	print(ans)


n = int(input())
for i in range(0, n):
	m = list(map(int, input().split()))[:3]
	if m[2] % m[0] == 0:
		if m[1] == 0:
			d = m[2]
		else:
			f = m[2] - m[0]
			d = f + m[1]
	else:
		f = m[2] // m[0]
		g = f * m[0]
		s = g + m[1]
		if s > m[2]:
			g = (f - 1) * m[0]
			d = g + m[1]
		else:
			d = s
	print(d)


t = int(input())
for i in range(t):
	(x, y, n) = list(map(int, input().split()))
	z = n % x
	if z == y:
		print(n)
	elif z >= y:
		print(n - z + y)
	else:
		print(n - z - (x - y))


def f(x, y, n):
	a = n % x
	b = y % x
	if a == b:
		return n
	elif a > b:
		return n - a + b
	else:
		return n - a - x + b
t = int(input())
for i in range(0, t):
	(x, y, n) = map(int, input().split())
	print(f(x, y, n))


n = int(input())
for i in range(n):
	(x, y, n) = map(int, input().split())
	p = n % x
	q = abs(p - y)
	if p > y:
		print(n - (p - y))
	if y > p:
		print(n - (x - q))
	if p == y:
		print(n)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin, stdout
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
import math
import time
from queue import Queue

def seive(n):
	l = [True]
	l = l * (n + 1)
	for i in range(2, int(sqrt(n)) + 1):
		if l[i] == True:
			val = i * i
			while val < len(l):
				l[val] = False
				val += i
	prime = []
	for i in range(2, len(l)):
		if l[i] == True:
			prime.append(i)
	return prime

def dp(l, i, n, val, ans):
	if i >= n or val < 0:
		return 1000000
	elif val == 0:
		return 0
	else:
		if ans[i] == 1000000:
			ans[i] = min(min(1 + dp(l, i + 1, n, val - l[i], ans), 1 + dp(l, i, n, val - l[i], ans)), dp(l, i + 1, n, val, ans))
		return ans[i]
from queue import Queue

def factors(n):
	l = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def check1(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v -= 1

def check2(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v += 1

def up(n):
	j = n - 1
	while j > 0:
		if n % j == 0:
			break
		j -= 1
	return j
t = int(stdin.readline())
for i in range(t):
	(x, y, n) = map(int, stdin.readline().split(' '))
	val = n // x
	if val * x + y > n:
		print((val - 1) * x + y)
	else:
		print(val * x + y)


t = int(input())
for i in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	a = n // x
	if n % x == y:
		print(n)
	elif n % x == y:
		print(n)
	else:
		z = max(a * x + y, (a - 1) * x + y)
		if z < n:
			print(z)
		else:
			print(min(a * x + y, (a - 1) * x + y))


from sys import stdin
from math import ceil
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(x, y, n) = [int(x) for x in inp().split()]
	c = n % x
	if c < y:
		n -= c
		n -= x - y
	else:
		n -= c - y
	print(n)


import sys
test_cases = int(input())
while test_cases != 0:
	test_cases -= 1
	(x, y, n) = [int(e) for e in input().split(' ')]
	print(n - (n - y) % x)


def find_k():
	(x, y, n) = map(int, input().split())
	w = n // x
	if w * x + y <= n:
		print(w * x + y)
	else:
		print(x * (w - 1) + y)
t = int(input())
for i in range(t):
	find_k()


T = int(input())
for _ in range(1, T + 1):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	count = int(n / x) * x
	rem = y % x
	s = count + rem
	if s > n:
		s = s - x
		print(s)
	else:
		print(s)


def requiredRemainder(x: int, y: int, n: int) -> None:
	if n < x + y:
		print(y)
		return
	else:
		if x * (n // x) + y > n:
			x *= n // x - 1
		else:
			x *= n // x
		print(x + y)
		return
test_cases = int(input())
for _ in range(test_cases):
	inputs = input().split(' ')
	requiredRemainder(int(inputs[0]), int(inputs[1]), int(inputs[2]))


cases = int(input())
for t in range(cases):
	(x, y, n) = list(map(int, input().split()))
	w = n % x
	if y > w:
		d = y - w
		print(n - x + d)
	elif y < w:
		d = w - y
		print(n - d)
	else:
		print(n)


import copy
nn = int(input())
while nn > 0:
	nn -= 1
	(x, y, n) = map(int, input().split())
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


for _ in range(int(input())):
	(x, y, k) = map(int, input().split())
	n = k // x
	m = n * x + y
	if m <= k:
		print(m)
	else:
		while m > k:
			m = m - x
		print(m)


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))
t = int(input())
for ti in range(1, t + 1):
	(x, y, n) = int_input()
	k = n % x
	if k >= y:
		print(n - (k - y))
	else:
		print(n - x + (y - k))


from sys import stdin

def solve(x, y, n):
	if n % x == y:
		print(n)
	elif n % x > y:
		print(n - (n % x - y))
	else:
		print(n - x + (y - n % x))
t = int(stdin.readline())
for _ in range(t):
	(x, y, n) = list(map(int, stdin.readline().rstrip().split()))
	solve(x, y, n)


t = int(input())
for case in range(t):
	(x, y, n) = map(int, input().split())
	o_n = n
	n -= n % x
	if n + y <= o_n:
		k = n + y
	else:
		k = n - x + y
	print(k)


try:
	for _ in range(int(input())):
		(x, y, n) = map(int, input().split())
		tem = n - y
		tem2 = tem // x
		print(tem2 * x + y)
except:
	pass


for i in range(int(input())):
	(x, y, n) = input().split()
	(x, y, n) = (int(x), int(y), int(n))
	num = (n - y) // x
	print(y + num * x)


import sys

def swap(x, y, a):
	temp = a[x]
	a[x] = a[y]
	a[y] = temp
	return a

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
		q[i] = [int(x) for x in q[i]]
	for i in range(1, len(q)):
		x = q[i][0]
		y = q[i][1]
		n = q[i][2]
		temp = n % x
		if y <= temp:
			n -= temp - y
		else:
			n = n - temp - (x - y)
		print(n)
main()


s = int(input())
for a in range(s):
	(h, i, t) = map(int, input().split())
	u = int((t - i) % h)
	v = t - u
	print(int(v))


for ii in range(int(input())):
	(x, y, n) = [int(x) for x in input().split()]
	xq = n - y
	rem = xq % x
	xq = xq - rem
	print(xq + y)


t = int(input())
for ts in range(t):
	(x, y, n) = map(int, input().split())
	c = (n - y) // x
	print(c * x + y)


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(x, y, n) = cin()
	t = n // x * x + y
	if t > n:
		t = (n // x - 1) * x + y
	print(t)


t = int(input())
while t > 0:
	(x, y, n) = [int(i) for i in input().split()]
	p = n // x * x
	q = n - p
	if q >= y:
		print(p + y)
	else:
		p = p - x
		print(p + y)
	t -= 1


ans = []
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	k = n - (n - y) % x
	ans.append(k)
for i in ans:
	print(i)


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	(x, y, n) = list(map(int, sys.stdin.readline().rstrip().split()))
	re = int(n / x) * x + y
	if re > n:
		re -= x
	print(re)


from sys import stdin
import random
from math import *
from random import randint
from collections import deque

def splt():
	return map(int, stdin.readline().split())

class Required:
	a = 0
	b = 0
	n = 0
	ans = 0

	def __init__(self, a, b, n):
		self.a = a
		self.b = b
		self.n = n

	def creatans(self):
		w = self.a
		ww = self.b
		www = self.n
		self.ans = www - ww
		self.ans = self.ans // w
		self.ans = self.ans * w

	def disp(self):
		print(self.ans + self.b)
test = int(input())
for x in range(test):
	(a, b, n) = splt()
	obj = Required(a, b, n)
	obj.creatans()
	obj.disp()


import sys
input = iter(sys.stdin.read().splitlines()).__next__
sys.setrecursionlimit(10000)
TC = int(input())
ans = []
for tc in range(TC):
	(x, y, n) = map(int, input().split())
	m = n // x
	res = x * m + y
	if res > n:
		res -= x
	ans.append(res)
print('\n'.join(map(str, ans)))


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			(x, y, n) = [int(x) for x in R().split()]
			mul = (n - y) // x
			ans.append(str(mul * x + y))
		W('\n'.join(ans))

def main():
	s = SOLVE()
	s.solve()
main()


def ans(x, y, n):
	r = n % x
	if n - r + y <= n:
		return n - r + y
	else:
		return n - r + y - x
t = int(input())
L = []
for i in range(t):
	(x, y, n) = map(int, input().split())
	L.append(ans(x, y, n))
for l in L:
	print(l)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	(x, y, n) = vars()
	num = n // x * x
	if num + y <= n:
		print(num + y)
	else:
		print(num - (x - y))
t = int(input())
for _ in range(t):
	main()


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	y1 = n % x
	if y1 > y:
		print(n - abs(y1 - y))
	elif y1 < y:
		print(n + abs(y1 - y) - x)
	else:
		print(n)


t = int(input())
a = []
for _ in range(t):
	(x, y, n) = map(int, input().split())
	mxmult = n // x * x
	if mxmult + y <= n:
		a.append(mxmult + y)
	else:
		a.append((n // x - 1) * x + y)
print(*a, sep='\n')


for i in range(int(input())):
	(x, y, z) = input().split()
	x = int(x)
	y = int(y)
	z = int(z)
	if z % x == y:
		print(z)
	else:
		z = z - y
		k = z % x
		print(z - k + y)


import sys
import time
a = int(sys.stdin.readline())
l = {}
for i in range(a):
	l.update({i: sys.stdin.readline().split()})
x = 0
y = 0
t = 0
r = 0
for k in range(a):
	x = int(l[r][0])
	y = int(l[r][1])
	t = int(l[r][2])
	r += 1
	rem = t % x
	if rem - y >= 0:
		print(t - (rem - y))
	else:
		print(t - rem - x + y)
	t -= 1


for _ in range(int(input())):
	arr = list(map(int, input().split()))
	print(arr[2] - (arr[2] - arr[1]) % arr[0])


t = int(input())
for T in range(t):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	elif n % x > y:
		r = n % x
		print(n - (r - y))
	else:
		s = n // x
		print(s * x - (x - y))


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	d = n % x
	if n - d + y > n:
		print(n - d + y - x)
	else:
		print(n - d + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if x < y:
		print(0)
	else:
		number = n - y
		reminder = number % x
		print(number - reminder + y)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	t = n // x * x
	if t + y <= n:
		print(t + y)
	elif t % x == y % x:
		print(t)
	else:
		p = x - y % x
		t = t - p
		print(t)


def solve(x, y, n):
	modulo = n % x
	if modulo >= y:
		return n - (modulo - y)
	return n - (x - y + modulo)
for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	print(solve(x, y, n))


import math
for _ in range(int(input())):
	(x, y, n) = input().split()
	n = int(n)
	x = int(x)
	y = int(y)
	k = x * math.floor((n - y) / x) + y
	print(k)


import math
elem = int(input())
for i in range(elem):
	ar = []
	for j in input().split(' '):
		ar.append(int(j))
	x = ar[0]
	y = ar[1]
	n = ar[2]
	print(int(x * math.floor((n - y) / x) + y))


for n in range(int(input())):
	(x, y, n) = map(int, input().split())
	p = (n - y) // x
	print(p * x + y)


for u in range(int(input())):
	(x, y, n) = map(int, input().split())
	t = n // x
	t = t * x
	if t + y > n:
		print(t - abs(x - y))
	else:
		print(y + t)


n = int(input())
for i in range(n):
	(m, n, b) = [int(i) for i in input().split()]
	c = b % m
	if c >= n:
		d = c - n
		print(b - d)
	else:
		d = m - n + c
		print(b - d)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))

def solve():
	if n - n % x + y <= n:
		return n - n % x + y
	return n - n % x - (x - y)
t = inp()
for _ in range(t):
	arr = inlt()
	x = arr[0]
	y = arr[1]
	n = arr[2]
	print(solve())


for i in range(int(input())):
	(x, t, p) = map(int, input().split())
	print(p - (p - t) % x)


for t in range(int(input())):
	(x, y, n) = map(int, input().split(' '))
	if n % x == y:
		print(n)
		continue
	else:
		r = n % x
		if r > y:
			ans = n - r + y
			print(ans)
			continue
		else:
			ans = n - r - x + y
			print(ans)


t = int(input())
for _ in range(t):
	l = input().split()
	(x, y, n) = (int(l[0]), int(l[1]), int(l[2]))
	q = n // x
	if n - x * q >= y:
		print(x * q + y)
	else:
		print(x * (q - 1) + y)


from sys import stdin
for _ in range(int(stdin.readline())):
	(x, y, n) = list(map(int, stdin.readline().split()))
	t = n // x
	res = t * x + y
	if res > n:
		res -= x
	print(res)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	t = c // a * a + b
	print(t if t <= c else t - a)


t = int(input())
count = 0
ans = []
while count < t:
	i = input()
	(x, y, n) = i.split()
	mod = int(n) // int(x)
	if abs(int(x) * mod - int(n)) < int(y):
		mod -= 1
	if mod < 0:
		mod = 0
	mod = int(x) * mod + int(y)
	ans.append(mod)
	count += 1
for y in ans:
	print(y)


from copy import copy, deepcopy

def read_int():
	return int(input())

def read_arr():
	return [int(x) for x in input().split(' ')]

def read_mx(n, m):
	return [[int(num) for num in input().split(' ')] for _ in range(0, n)]

def work(p_case):
	(x, y, n) = read_arr()
	z = n % x
	mx = n - z
	k = mx + y
	if k > n:
		k -= x
	print(k)
t = read_int()
for case in range(0, t):
	work(case + 1)


import sys, collections, math

def in_out():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	rem = n % x
	if rem == y:
		print(n)
	elif rem > y:
		rem -= y
		n = n - rem
		print(n)
	else:
		n -= rem
		n -= x - y
		print(n)


n = int(input())
for i in range(0, n):
	x = list(map(int, input().split()))
	a = x[0]
	b = x[1]
	c = x[2]
	diff = a - b
	diff2 = c - a * int(c / a)
	y = int(c / a) * a
	if diff2 >= b:
		print(y + b)
	else:
		print(y - diff)


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	su = n % x
	su1 = su - y
	print(n - su1 % x)


t = int(input())
for j in range(0, t):
	xyn = input()
	x_y_n = xyn.split()
	for i in range(0, 3):
		x_y_n[i] = int(x_y_n[i])
	rest = x_y_n[2] % x_y_n[0]
	help = x_y_n[2] - rest
	if x_y_n[1] > rest:
		k = help - x_y_n[0] + x_y_n[1]
	else:
		k = help + x_y_n[1]
	print(k)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	c = n % x
	if y <= c:
		result = n - (c - y)
	else:
		result = n - c - (x - y)
	print(result)


import math as mt

def tran(arr):
	(x, y) = (arr[0], arr[1])
	n = arr[2] % x
	if n > y:
		return arr[2] - (n - y)
	elif n == y:
		return arr[2]
	else:
		return arr[2] - (x - (y - n))
t = int(input())
ans = []
for i in range(t):
	arr = list(map(int, input().rstrip().split()))
	r = tran(arr)
	ans.append(r)
for i in ans:
	print(i)


n = int(input())
while n > 0:
	p = list(map(int, input().split()))
	x = int(p[2] / p[0])
	if p[0] * x + p[1] > p[2]:
		print(p[0] * (x - 1) + p[1])
	else:
		print(p[0] * x + p[1])
	n = n - 1


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	cnt = n // x
	ans = x * cnt + y
	if ans > n:
		ans -= x
	print(ans)


def main():
	t = int(input())
	while t > 0:
		(x, y, n) = map(int, input().split())
		num = n // x * x + y
		num1 = (n // x - 1) * x + y
		if num <= n:
			print(num)
		else:
			print(num1)
		t -= 1
main()


def check(m, n):
	pass
t = int(input())
while t:
	(x, y, n) = list(map(int, input().split()))
	a = n // x
	if a * x + y <= n:
		print(a * x + y)
	else:
		print((a - 1) * x + y)
	t -= 1


tc = int(input())
for ctr in range(tc):
	(x, y, n) = map(int, input().split())
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


test_case = int(input())
for _ in range(test_case):
	(x, y, n) = map(int, input().split())
	zero_value = n // x * x
	gap = n - zero_value
	if y <= gap:
		print(zero_value + y)
	else:
		print(zero_value - x + y)


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	(x, y, n) = map(int, stdin.readline().strip().split())
	z = (n - y) // x
	print(y + x * z)


testCases = int(input())
for case in range(testCases):
	(x, y, n) = map(int, input().split())
	qMax = (n - y) // x
	kMax = x * qMax + y
	print(kMax)


for tc in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n < x:
		print(y)
	else:
		rem = n % x
		if rem < y:
			print(n - rem - x + y)
		elif rem > y:
			print(n - rem + y)
		else:
			print(n)


t = int(input())
while t:
	inp1 = list(map(int, input().strip().split()))[:3]
	(x, y, n) = (inp1[0], inp1[1], inp1[2])
	val = n - n % x + y
	val1 = n - n % x - (x - y)
	if x == 0:
		print(0)
	elif val <= n:
		print(val)
	else:
		print(val1)
	t -= 1


import sys
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	q = n // x
	k = q * x + y
	k = k if k <= n else k - x
	sys.stdout.write(str(k) + '\n')


t = int(input())
for _ in range(t):
	(a, b, c) = list(map(int, input().split()))
	z = c % a
	x = (z - b) % a
	print(c - x)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	v = c % a
	if v == b:
		print(c)
	elif v > b:
		print(c - (v - b))
	else:
		print(c - v - (a - b))


t = input()
t = int(t)
for i in range(t):
	(x, y, n) = input().split(' ')
	x = int(x)
	y = int(y)
	n = int(n)
	b = n - y
	if b == x:
		print(n)
		continue
	if n - y < x:
		print(y)
		continue
	if b > x:
		f = b % x
		d = b - f + y
		print(d)
		continue


t = int(input())
for _ in range(0, t):
	(x, y, n) = map(int, input().split())
	a = n % x
	k = 0
	q = 0
	r = 0
	if a == y:
		k = n
	else:
		r = y - a
		if r > 0:
			q = a + (x - y)
			k = n - q
		else:
			k = n - (a - y)
	print(k)


t = int(input())
arr = []
for _ in range(t):
	(x, y, n) = map(int, input().split())
	arr.append([x, y, n])
for (x, y, n) in arr:
	(d, r) = divmod(n, x)
	if d == 0:
		print(y)
	elif r == y:
		print(n)
	elif r < y:
		print(x * (d - 1) + y)
	else:
		print(x * d + y)


val = input()
for i in range(int(val)):
	(x, y, n) = str.split(input())
	mod = int(n) % int(x)
	if mod == int(y):
		print(int(n))
	elif mod > int(y):
		print(int(n) - (int(mod) - int(y)))
	else:
		print(int(n) - int(mod) - (int(x) - int(y)))


a = int(input())
for i in range(a):
	(x, y, z) = map(int, input().split())
	b = z % x
	if y > b:
		z -= x
	print(z - (b - y))


import math
import sys

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		if v not in self.adj_list[u]:
			self.adj_list[u].append(v)
		if self.is_directed == False:
			if u not in self.adj_list[v]:
				self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print(node, '->', self.adj_list[node])

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		parents.append(v)
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 5)
		parents = []
		self.dfsUTIL(v, visited, parents)
		return parents

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(x, a, b, c):
	return a * x * x + b * x + c

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())
for _ in range(int(input())):
	(x, y, n) = mult_inp()
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
		continue
	else:
		o = n
		n = n - n % x
		if n + y > o:
			k = n - (x - y) % x
			print(k)
		else:
			k = n + y
			print(k)


p = int(input())
while p:
	(a, b, c) = [int(i) for i in input().split(' ')]
	if c % a > b:
		c = c - (c % a - b)
	elif c % a < b:
		c = c - c % a - (a - b)
	print(c)
	p = p - 1


def main():
	for i in range(int(input())):
		(a, b, c) = map(int, input().split())
		res = c % a
		c -= res
		if res >= b:
			print(c + b)
		else:
			print(c - (a - b))
main()


tc = int(input())
for i in range(tc):
	(x, y, n) = map(int, input().split())
	mul = int((n - y) / x)
	ans = mul * x + y
	print(int(ans))


import math

def perform_bubble_sort(blist):
	(cmpcount, swapcount) = (0, 0)
	blist = list(map(int, input().split()))
	for j in range(len(blist)):
		for i in range(1, len(blist) - j):
			cmpcount += 1
			if blist[i - 1] > blist[i]:
				swapcount += 1
				(blist[i - 1], blist[i]) = (blist[i], blist[i - 1])
	print(swapcount)

def fun(l, c, d):
	if c == n:
		return d
	if c % 2 == 0:
		d = max(fun(l[:-1], c + 1, d + l[-1]), fun(l[1:], c + 1, d + l[0]))
	else:
		d = min(fun(l[1:], c + 1, d - l[0]), fun(l[:-1], c + 1, d - l[-1]))
	return d
t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		k = n % x
		a = 0
		if k < y:
			a = n - x + abs(k - y)
		else:
			a = n - abs(k - y)
		print(a)


t = int(input(''))
for i in range(0, t):
	(a, b, c) = input('').split(' ')
	x = int(a)
	y = int(b)
	n = int(c)
	k = n % x
	if k >= y:
		p = k - y
		print(n - p)
	else:
		j = n - k
		print(j - x + y)


from sys import *
t = int(stdin.readline())
while t > 0:
	(x, y, n) = map(int, stdin.readline().split())
	de = n % x
	if de == y:
		ans = n
	elif de > y:
		ans = n - (de - y)
	elif de < y:
		ans = n - de - x + y
	print(ans)
	t -= 1


import math
from sys import stdin
from collections import Counter, defaultdict, deque
input = stdin.readline
mod = pow(10, 9) + 7

def solve():
	(x, y, n) = map(int, input().split())
	z = n % x
	if z == y:
		print(n)
	elif y < z:
		print(n - z + y)
	else:
		print(n - z - x + y)
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	if y <= n % x:
		print(n - n % x + y)
	elif n + y >= x + n % x:
		print(n - n % x + y - x)
	else:
		print('NO SUCH INTEGER EXITS')


from math import *
l = int(input())
lo = []
for i in range(l):
	(x, y, n) = list(map(int, input().split()))
	a = floor((n - y) / x)
	lo.append(a * x + y)
for i in lo:
	print(i)


t = int(input())
for tc in range(t):
	line = input().split()
	(x, y, n) = (int(line[0]), int(line[1]), int(line[2]))
	k = n
	if n % x == y:
		ans = n
	else:
		current = n % x
		req = current - y
		if req > 0:
			ans = n - req
		else:
			ans = n - req - x
	print(ans)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	a = n - y
	p = a // x
	k = p * x + y
	print(k)


test = int(input())
for j in range(test):
	(x, y, n) = map(int, input().split())
	q = n // x
	new = q * x
	new += y
	if new <= n:
		print(new)
	else:
		print((q - 1) * x + y)


testcase = int(input())
while testcase:
	testcase -= 1
	ip = list(map(int, input().split()))
	(x, y, n) = (ip[0], ip[1], ip[2])
	mod1 = y % x
	mod2 = n % x
	if mod1 == mod2:
		print(n)
		continue
	elif mod1 < mod2:
		print(n - mod2 + mod1)
	else:
		print(n - mod2 - x + mod1)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from copy import copy
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(x, y, n) = map(int, input().split())
		if n % x == y:
			print(n)
		elif n % x > y:
			v = n - (n % x - y)
			print(v)
		else:
			n -= x
			ans = n
			ans += y - n % x
			print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	t = int(input())
	for _ in range(t):
		(a, b, n) = map(int, input().split())
		div = n // a
		if n - div * a < b:
			ans = (div - 1) * a + b
		else:
			ans = div * a + b
		print(ans)
main()


def solve():
	(x, y, n) = map(int, input().split())
	a = n % x
	if a == y:
		return n
	if a > y:
		return n - (a - y)
	else:
		c = x - y
		return n - (a + c)
for _ in range(int(input())):
	print(solve())


t = int(input())
for i in range(t):
	xi = input().split(' ')
	x = int(xi[0])
	y = int(xi[1])
	n = int(xi[2])
	m = int(n / x)
	if m * x + y <= n:
		print(str(m * x + y))
	else:
		m -= 1
		print(str(m * x + y))


t = int(input())
for i in range(t):
	(x, y, n) = [int(i) for i in input().split()[:3]]
	f = (n - y) // x
	f2 = f * x + y
	print(f2)


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	b = n // x
	c = b * x + y
	if c > n:
		c -= x
	print(c)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n < x:
		print(y)
		continue
	elif y == 0 and n >= x:
		print(n // x * x)
	else:
		r = n // x
		q = x * r + y
		if q > n:
			q = x * (r - 1) + y
			print(q)
		else:
			print(q)


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = 998244353
for t in range(int(data())):
	(x, y, n) = mdata()
	k = n % x
	if k >= y:
		n -= k - y
	else:
		n -= x - (y - k)
	out(n)


from heapq import *
from collections import *
import os
import sys
from io import BytesIO, IOBase
import math

def dfs(vis, good, cur, d, dc, step, mn, p):
	if cur == d:
		mn[0] = min(mn[0], step)
		return True
	vis.add(cur)
	f = False
	for nbr in dc[cur]:
		if nbr not in vis and nbr in good and (nbr != p):
			f = dfs(vis, good, nbr, d, dc, step + 1, mn, cur)
	return f
ins = lambda : [int(x) for x in input()]
inp = lambda : int(input())
inps = lambda : [int(x) for x in input().split()]

def main():
	t = inp()
	for i in range(t):
		(x, y, n) = inps()
		rem = n % x
		if rem >= y:
			print(n - (rem - y))
		else:
			print(n - rem - (x - y))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	res = n // x
	if n % x == y:
		print(n)
	elif n % x > y:
		val = n % x
		val -= y
		print(n - val)
	else:
		res -= 1
		res *= x
		res += y
		print(res)


def solve(x, y, n):
	mod = n % x
	if mod == y:
		print(n)
	elif mod > y:
		n -= mod - y
		print(n)
	else:
		n = n - mod - (x - y)
		print(n)
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	solve(x, y, n)


def req(x, y, n):
	p = int((n - y) / x)
	k = p * x + y
	return k
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	print(req(x, y, n))


T = int(input())
for t in range(T):
	(x, y, n) = [int(i) for i in input().split()]
	y %= x
	nr = n % x
	if nr < y:
		print(n - nr - (x - y))
	else:
		print(n - nr + y)


t = int(input())
for i in range(t):
	(x, y, n) = [int(j) for j in input().split()]
	m = (n - y) // x
	print(y + m * x)


t = int(input())
for i in range(0, t):
	xyn = input().split()
	x = int(xyn[0])
	y = int(xyn[1])
	n = int(xyn[2])
	r = n % x
	if y == r:
		print(n)
	elif r > y:
		print(n - r + y)
	else:
		print(n - r + y - x)


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	(x, y, n) = mp()
	h = n // x
	ans = h * x + y
	if ans > n:
		print(ans - x)
	else:
		print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	num = n // x
	num1 = num * x + y
	if num1 > n:
		num1 = num1 - x
	print(num1)


List = []
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	Quotient = int((n - y) / x)
	Dividend = x * Quotient + y
	List.append(Dividend)
for Content in List:
	print(Content)


import sys
read = lambda : sys.stdin.readline()
T = int(read())
for t in range(T):
	(x, y, n) = map(int, read().split())
	print((n - y) // x * x + y)


import sys
import math
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	(x, y, n) = intInp()
	z = (n - y) // x
	print(y + x * z)


def check(x, y, n):
	t = n % x
	if t == y:
		return n
	if t > y:
		return n - t + y
	if t < y:
		return n - t - x + y
t = int(input())
for x in range(0, t):
	(x, y, n) = map(int, input().split())
	print(check(x, y, n))


for i in range(int(input())):
	(a, b, n) = map(int, input().split(' '))
	r = n % a
	x = n - r
	while x + b > n:
		x = x - a
	print(x + b)


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n % x
	b = (a - y) % x
	ans = n - b
	print(ans)


for test in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		a = r - y
		print(n - a)
	else:
		n -= x
		a = y - r
		print(n + a)


import math
t = int(input())
for _ in range(0, t):
	(x, y, n) = map(int, input().split())
	floor = math.floor(n // x)
	maxi = x * floor + y
	if maxi > n:
		print((floor - 1) * x + y)
	else:
		print(floor * x + y)


tt = int(input())
for loop in range(tt):
	(x, y, n) = list(map(int, input().split()))
	tmp = n // x * x + y
	if tmp > n:
		tmp -= x
	print(tmp)


t = int(input())
for i in range(t):
	(y, l, n) = map(int, input().split())
	Z = n - (n - l) % y
	print(Z)


import sys
input = sys.stdin.readline
t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	a = n // x * x
	aa = a + y
	while aa > n:
		aa -= x
	print(aa)
	t -= 1


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(a, b, n) = li()
	temp = n // a
	ans = b + a * temp
	if ans > n:
		ans -= a
	print(ans)


def f(x, y, n):
	r = n % x
	m = n - r
	if m + y <= n:
		return m + y
	return m - x + y
t = int(input())
for _ in range(t):
	(x, y, n) = tuple(map(int, input().split()))
	print(f(x, y, n))


t = int(input())
while t:
	(x, y, n) = [int(i) for i in input().split()]
	div = n // x
	if x * div + y <= n:
		print(x * div + y)
	else:
		print(x * (div - 1) + y)
	t -= 1


def f(x, y, n):
	if n % x == y:
		return n
	if n % x < y:
		n -= x
	return n + y - n % x

def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = list(map(int, input().split()))
		print(f(x, y, n))
main()


def main():
	t = int(input())
	for i in range(t):
		s = str(input())
		s = s.split()
		x = int(s[0])
		y = int(s[1])
		n = int(s[2])
		ans = (n - y) // x * x + y
		print(ans)
main()


size = int(input())
for i in range(size):
	mx = 1
	ls = list(map(int, input().split()))
	for i in ls:
		if mx < i:
			mx = i
	rem = mx % ls[0]
	if rem >= ls[1]:
		if rem == 0 and ls[1] == 0 and (ls[0] > ls[2]):
			print(rem)
		else:
			subs = rem - ls[1]
			print(mx - subs)
	else:
		rem = mx % ls[0]
		rem = ls[1] - rem
		print(mx - (ls[0] - rem))


t = int(input())
for hatt in range(t):
	lis = input().split()
	(x, y, n) = (int(lis[0]), int(lis[1]), int(lis[2]))
	lam = (n - y) // x
	k = y + lam * x
	print(k)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	quo = n // x
	ans = -1
	while 1:
		ans = x * quo + y
		if ans > n:
			quo = quo - 1
		else:
			break
	print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	n2 = n - n % x
	zv1 = y % x
	zv2 = n % x
	ans = n - zv2 + zv1
	if ans > n:
		print(ans - x)
	else:
		print(ans)


t = int(input())
result = list()
integers = list()
for test_case in range(t):
	integers.clear()
	integers = input()
	integers = integers.split()
	integers = list(map(int, integers))
	dummy = (integers[2] - integers[1]) // integers[0]
	result.append(dummy * integers[0] + integers[1])
for i in result:
	print(i)


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	a = n // x * x + y
	if a <= n:
		print(a)
	else:
		dif = a - n
		b = dif // x + 1
		c = a - b * x
		print(c)


import math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)

def bs(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return arr[mid]
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def swap(list, pos1, pos2):
	(list[pos1], list[pos2]) = (list[pos2], list[pos1])
	return list
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	z = int(n / x)
	if z * x + y <= n:
		print(z * x + y)
	else:
		print((z - 1) * x + y)


t = int(input())
while t > 0:
	(x, y, n) = list(map(int, input().split()))
	reminder = n % x
	if reminder > y:
		ans = n - (reminder - y)
	elif reminder < y:
		ans = n - x + (y - reminder)
	elif y == reminder:
		ans = n
	print(ans)
	t -= 1


try:

	def check(x, y, n):
		div = n % x
		while n % x != y:
			if y <= div:
				n = n - (div - y)
			else:
				n = n - (div + 1)
				div = n % x
		return n
	for i in range(int(input())):
		(x, y, n) = list(map(int, input().split()))
		print(check(x, y, n))
except:
	pass


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(t,) = mp()
for _ in range(t):
	(x, y, n) = mp()
	m = n % x
	if m == y:
		cout(str(n) + '\n')
	elif y < m:
		cout(str(n + y - m) + '\n')
	else:
		cout(str(n - m - x + y) + '\n')


T = int(input())
while T != 0:
	a = list(map(int, input().strip().split()))[:3]
	(x, y, n) = (a[0], a[1], a[2])
	if n < x:
		print(y)
		T -= 1
		continue
	rem = n % x
	if rem >= y:
		ans = n - rem + y
		print(ans)
	else:
		n = n - rem
		ans = n - x + y
		print(ans)
	T -= 1


def rem(x, y, n):
	init = n // x
	mod = y % x
	formal = init * x + mod
	while formal > n:
		init -= 1
		formal = init * x + mod
	return formal
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	print(rem(x, y, n))


from math import *
from itertools import *
from collections import *

def ii():
	return int(input())

def mas():
	return [int(i) for i in input().split()]

def mapis():
	return map(int, input().split())
INF = 1000000000.0 + 1

def solve():
	(x, y, n) = mapis()
	k = n // x * x
	if k + y > n:
		print(k - x + y)
	else:
		print(k + y)

def main():
	t = ii()
	while t:
		solve()
		t -= 1
main()


for i in range(int(input())):
	a = list(map(int, input().strip().split()))[:3]
	j = a[2] % a[0]
	if j >= a[1]:
		a[2] = a[2] - (j - a[1])
	else:
		k = a[0] - a[1]
		a[2] = a[2] - j - k
	print(a[2])


import sys
t = int(input())

def inp():
	return sys.stdin.readline().strip()
for _ in range(t):
	(x, y, n) = map(int, inp().split())
	a = n % x
	if a >= y:
		n = n - (a - y)
		print(n)
	elif a < y:
		n = n + (y - a) - x
		print(n)


def main(x, y, n):
	index = int(n / x)
	i = index * x + y
	if i <= n:
		return i
	else:
		i = index * x - (x - y)
		return i
t = int(input())
for t_itr in range(t):
	xyn = list(map(int, input().rstrip().split()))
	x = xyn[0]
	y = xyn[1]
	n = xyn[2]
	res = main(x, y, n)
	print(res)


t = int(input())
for i in range(t):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	answer = n - (n % x - y)
	if answer > n:
		answer -= x
	print(answer)


t = int(input())
arr = []
ans = []
for i in range(t):
	s = input().split(' ')
	arr.append([int(s[0]), int(s[1]), int(s[2])])
	ans.append(arr[i][0] * int((arr[i][2] - arr[i][1]) / arr[i][0]) + arr[i][1])
for i in ans:
	print(i)


t = int(input())
for x in range(t):
	xyn = input().split()
	x = int(xyn[0])
	y = int(xyn[1])
	n = int(xyn[2])
	multiply = n // x
	if multiply * x + y > n:
		print((multiply - 1) * x + y)
	else:
		print(multiply * x + y)


import math
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		k = n % x
		if k < y:
			print(n - x + abs(y - k))
		else:
			print(n - abs(y - k))


test = int(input())
for i in range(test):
	(x, y, n) = map(int, input().split())
	rem = n % x
	no = n - rem + y
	if no <= n:
		print(no)
	else:
		print(no - x)


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	t1 = n % x
	t2 = n // x
	if t1 >= y:
		t3 = t2 * x + y
	else:
		t2 = t2 - 1
		t3 = t2 * x + y
	print(t3)


cases = int(input())
for _ in range(cases):
	(x, y, n) = list(map(int, input().strip().split()))
	f = int((n - y) / x)
	k = x * f + y
	print(k)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def solve(x, y, n):
	r = n % x
	n -= (r - y) % x
	return n

def main():
	mod = 1000000007
	inv = lambda x: pow(x, mod - 2, mod)
	t = int(input())
	for _ in range(t):
		(x, y, n) = map(int, input().split())
		ans = solve(x, y, n)
		sys.stdout.write(str(ans) + '\n')
main()


b = []

def Input():
	(x, y, n) = map(int, input().split())
	a = n % x
	if a >= y:
		b.append(n - a + y)
	else:
		b.append(n - a - x + y)
t = int(input())
for i in range(t):
	Input()
for i in range(t):
	print(b[i])


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	r = n // x
	if r * x + y > n:
		r = r - 1
	print(r * x + y)


t = int(input(''))
a = []
for i in range(t):
	(x, y, n) = map(int, input().split())
	tmp = n // x * x + y
	if tmp > n:
		tmp -= x
	a.append(tmp)
for i in range(t):
	print(a[i])


def req_rem(x, y, n):
	if n % x == y:
		return n
	elif n < x:
		return y
	else:
		q = n // x
		while True:
			if q * x + y < n:
				return q * x + y
			else:
				q -= 1
t = int(input())
for t_itr in range(t):
	arr = list(map(int, input().rstrip().split()))
	x = int(arr[0])
	y = int(arr[1])
	n = int(arr[2])
	result = req_rem(x, y, n)
	print(result)


import math

def solve():
	(x, y, n) = list(map(int, input().split()))
	rem = n // x
	rem *= x
	rem += y
	if rem > n:
		rem -= x
	print(rem)
t = 1
t = int(input())
for _ in range(0, t):
	solve()


import sys
T = int(sys.stdin.readline())
ans_arr = []
for t in range(T):
	[x, y, n] = [int(i) for i in sys.stdin.readline().split()]
	if n % x == y:
		ans_arr.append(str(n))
	else:
		val = n // x * x + y
		if val <= n:
			ans_arr.append(str(val))
		else:
			num = (n // x - 1) * x + y
			num = max(0, num)
			ans_arr.append(str(num))
print('\n'.join(ans_arr))


for _ in range(int(input().strip())):
	(x, y, n) = map(int, input().strip().split())
	temp = (n - y) // x
	temp1 = temp * x + y
	print(temp1)


for __ in range(int(input())):
	(x, y, n) = map(int, input().split())
	print((n - y) // x * x + y)


t = int(input())
for ex in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	it = 0
	while n - n % x - it * x + y > n:
		it += 1
	print(n - n % x - it * x + y)


def solve():
	(x, y, n) = [int(i) for i in input().split()]
	q = n // x * x + y
	if q > n:
		q -= x
	return q
t = int(input())
ans = []
while t:
	ans.append(str(solve()))
	t -= 1
print('\n'.join(ans))


t = int(input())
for i in range(t):
	line = input().split()
	x = int(line[0])
	y = int(line[1])
	n = int(line[2])
	temp_v = n % x
	if temp_v == y:
		print(n)
	elif temp_v < y:
		temp_var_2 = n - (temp_v + (x - y))
		print(temp_var_2)
	else:
		temp_var_2 = n - (temp_v - y)
		print(temp_var_2)


import math
import os
import random
import re
import sys
import collections

def solve():
	for _ in range(int(input())):
		(x, y, n) = map(int, input().strip().split())
		a = n // x
		b = n % x
		if b >= y:
			print(x * a + y)
		else:
			print(x * (a - 1) + y)
solve()


for _ in range(int(input())):
	(x, y, n) = [int(i) for i in input().split()]
	v = n // x
	ca = v * x
	if ca + y <= n:
		print(ca + y)
	else:
		v = n // x - 1
		ca = v * x
		print(ca + y)


for _ in range(int(input())):
	(x, req_rem, n) = map(int, input().split())
	max_rem = n % x
	if max_rem == req_rem:
		print(n)
	elif max_rem > req_rem:
		print(n - (max_rem - req_rem))
	else:
		quotient = n // x
		quotient -= 1
		print(quotient * x + req_rem)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def main():
	try:
		(x, y, n) = In()
		t = n // x
		t = t * x
		t += y
		if t > n:
			t -= x
		print(t)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	new = n + (y - a)
	if new > n:
		new = new - x
	print(new)


b = int(input())
for i in range(b):
	(x, y, n) = input().split(' ')
	(x, y, n) = (int(x), int(y), int(n))
	ans = 0
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


t = int(input())
for _ in range(t):
	ar = list(map(int, input().rstrip().split()))
	x = ar[0]
	y = ar[1]
	n = ar[2]
	i = n // x
	while i >= 0:
		k = i * x + y
		if k <= n:
			break
		i -= 1
	print(k)


T = int(input())
final = []
for _ in range(T):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a - y >= 0:
		n = n - (a - y)
	else:
		n = n - a - x + y
	final.append(n)
for i in final:
	print(i)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(x, y, n) = invr()
	ans = n // x * x + y
	if ans > n:
		ans -= x
	print(ans)


result = ''
for q in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = 0
	if n % x == y:
		print(n)
	else:
		m = n % x
		if m < y:
			n = n - m - (x - y)
		else:
			n = n - (m - y)
		print(n)


from functools import reduce
import collections
import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		(x, y, n) = Read.list_int()
		if n - n // x * x < y:
			print((n // x - 1) * x + y)
		else:
			print(n // x * x + y)
main()


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = c // a
	if ans * a + b <= c:
		print(ans * a + b)
	else:
		while ans * a + b > c:
			ans = ans - 1
		print(ans * a + b)


T = int(input())
for i in range(T):
	(a, b, c) = map(int, input().split())
	mo = c % a
	if mo >= b:
		val = c - (mo - b)
	else:
		c = c - a
		val = c + (b - mo)
	print(val)


TC = int(input())

def solution(l):
	(x, y, n) = (l[0], l[1], l[2])
	ans = n // x * x + y
	if ans > n:
		ans = ans - x
	print(ans)
	return
for _ in range(TC):
	l = list(map(int, input().split()))
	solution(l)


t = int(input())
ans = []
for t in range(t):
	s = input().split(' ')
	x = int(s[0])
	y = int(s[1])
	n = int(s[2])
	k = (n - y) // x
	ans.append(y + k * x)
for x in ans:
	print(x)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x == 0:
		ans = n - x + y
		if ans < 0:
			print(0)
		elif y == 0:
			print(n)
		else:
			print(ans)
	else:
		sub = n % x
		req = n - sub
		if req + y <= n:
			print(req + y)
		else:
			req = req - x
			print(req + y)


f = lambda x, y, n: n - (n % x - y) % x
print(*[f(*map(int, input().split())) for _ in range(int(input()))], sep='\n')


t = int(input())
for i in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	a = n // x
	ans = a * x + y
	if ans > n:
		ans = ans - x
	print(ans)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	n1 = n % x
	y1 = y % x
	if y1 > n1:
		print(n + y1 - n1 - x)
	else:
		print(n - n1 + y1)


import math
from collections import deque
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < abs(max_ending_here):
			max_so_far = max_ending_here
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	(x, y, n) = list(map(int, input().split()))
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		print(n - (r - y))
	else:
		n = n - (r + 1)
		r = n % x
		if r == y:
			print(n)
		elif r > y:
			print(n - (r - y))
t = int(input())
for i in range(0, t):
	main()


test_case = int(input())
for _ in range(test_case):
	(a, b, c) = map(int, input().split())
	y = c
	x = c % a
	if x != b:
		c -= x
		if c + b < y:
			c += b
		else:
			c -= a
			c += b
	print(c)


t = int(input())
for _ in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	ans = n - y
	o_ans = ans % x
	f_ans = n - o_ans
	print(f_ans)


t = int(input())
for i in range(t):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	q = n // x
	a = q * x + y
	if a > n:
		s = a - x
		print(s)
	else:
		print(a)


t = int(input())
while t:
	t -= 1
	arr = list(map(int, input().split()))
	(x, y, n) = (arr[0], arr[1], arr[2])
	rem = n % x
	if y == rem:
		print(n)
	elif y > rem:
		n -= rem
		n -= x - y
		print(n)
	elif y < rem:
		n -= rem - y
		print(n)


t = int(input())
for qwe in range(t):
	(x, y, n) = map(int, input().split())
	a = n // x
	if n - x * a >= y:
		print(x * a + y)
	else:
		print(x * (a - 1) + y)


def rem(x, y, n):
	val = n % x
	mini = val - y
	if y <= val:
		return n - mini
	else:
		return n - (x + mini)
T = int(input())
for t in range(T):
	numbers = list(map(int, input().split()))
	(x, y, n) = (numbers[0], numbers[1], numbers[2])
	ans = rem(x, y, n)
	print(ans)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, input().split()))

def In():
	return map(int, input().split())

def I():
	return int(input())
P = 1000000007

def main():
	for t in range(I()):
		(x, y, n) = In()
		v = (n - y) // x
		print(max(0, v * x + y))
main()


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	ans = 0
	if n % x == y:
		print(n)
		continue
	if n % x > y:
		print(n - (n % x - y))
		continue
	print(n - n % x - (x - y))


def main():
	t = int(input())
	while t:
		(x, y, n) = map(int, input().split())
		n -= y
		m = n // x
		print(m * x + y)
		t -= 1
main()


from math import floor
n = int(input())
f = 0
l = []
for i in range(n):
	l.append(list(input().split()))
for j in range(len(l)):
	x = int(l[j][0])
	y = int(l[j][1])
	z = int(l[j][2])
	max_factor = floor(z / x)
	while max_factor * x + y > z:
		max_factor -= 1
	print(max_factor * x + y)


T = int(input())

def solve(x, y, n):
	r = (n - y) % x
	return n - r
while T > 0:
	(x, y, n) = [int(el) for el in input().split(' ')]
	print(solve(x, y, n))
	T -= 1


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	print(y + (n - y) // x * x)


t = int(input())
l = []
for e in range(0, t):
	(x, y, n) = [int(x) for x in input().split(' ')]
	if n - n % x + y <= n:
		l.append(n - n % x + y)
	else:
		l.append(n - n % x + y - x)
for i in l:
	print(i)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	val = n // x
	while val >= 0:
		num = x * val + y
		val -= 1
		if num <= n:
			break
	print(num)


T = int(input())
for i in range(T):
	(x, y, n) = list(map(int, input().split()))
	rem = n // x
	k = x * rem + y
	if k > n:
		k -= x
	print(k)


T = int(input())
for _ in range(T):
	(X, Y, N) = map(int, input().split())
	MOD_VAL = N % X
	if MOD_VAL == Y:
		print(N)
	elif MOD_VAL < Y:
		N = N - MOD_VAL
		print(N - (X - Y))
	else:
		print(N - (MOD_VAL - Y))


te = int(input())
for i in range(te):
	(x, y, n) = input().split(' ')
	n = int(n)
	x = int(x)
	y = int(y)
	if y == 0 and n < x:
		print('0')
	else:
		t = n % x
		if t == y:
			print(n)
		else:
			if t > y:
				t = t - y
			else:
				t = t + (x - y)
			n = n - t
			print(n)


from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
	(x, y, n) = list(map(int, stdin.readline().strip().split(' ')))
	diff = (n - y) % x
	print(n - diff)


def solve(x, y, n):
	m = n % x - y
	if m < 0:
		m += x
	return n - m
t = int(input())
for i_t in range(t):
	current_str = input().split(' ')
	x = int(current_str[0])
	y = int(current_str[1])
	n = int(current_str[2])
	print(solve(x, y, n))


def remainder(x, y, n):
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x + y - x)
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	remainder(x, y, n)


t = int(input())
while t:
	ls = list(map(int, input().split()))
	if ls[2] % ls[0] >= ls[1]:
		print(ls[2] - (ls[2] % ls[0] - ls[1]))
	else:
		print(ls[2] - ls[0] - ls[2] % ls[0] + ls[1])
	t -= 1


from math import log, floor

def find(x, y, n):
	return x * floor(n / x) + y if x * floor(n / x) + y <= n else x * floor(n / x - 1) + y
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	print(find(x, y, n))


t = int(input())
l = []
for i in range(t):
	I = lambda : map(int, input().split())
	(x, y, n) = I()
	c = n - n % x + y
	if c > n:
		print(c - x)
	else:
		print(c)


t = int(input())
while t:
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	m = n % x
	if m < y:
		print(n - (x - y + m))
	else:
		print(n - (m - y))
	t -= 1


import sys
t = int(sys.stdin.readline())
while t:
	(x, y, n) = map(int, sys.stdin.readline().strip().split())
	rem = n % x
	if rem < y:
		sub = rem + (x - y)
		print(n - sub)
	elif rem == y:
		print(n)
	else:
		print(n - (rem - y))
	t -= 1


from sys import stdin

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	(x, y, n) = minput()
	k = (n - y) // x
	print(y + k * x)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	k = n % x
	n2 = n - k
	n2 += y
	while 1:
		if n2 > n:
			n2 -= x
		else:
			break
	print(n2)


def main():
	ans = 0
	for i in range(int(input())):
		(x, y, n) = [int(i) for i in input().split()]
		if y == 0:
			ans = n - n % x
		else:
			a = n - n % x + y
			b = n - n % x - (x - y)
			if a > n:
				ans = b
			else:
				ans = a
		print(ans)
main()


t = int(input())
for z in range(t):
	(x, y, n) = map(int, input().split())
	div = n // x
	if div * x + y <= n:
		print(div * x + y)
	else:
		div -= 1
		print(div * x + y)


import sys

def get_ints():
	return map(int, I().strip().split())

def get_list():
	return list(map(int, I().strip().split()))
I = sys.stdin.readline
for _ in range(int(I())):
	(x, y, n) = get_ints()
	a = n - y
	b = a // x
	print(b * x + y)


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	dif = n % x
	if dif == y:
		print(n)
	elif dif > y:
		mi = dif - y
		print(n - mi)
	else:
		ans = n - dif - (x - y)
		print(ans)


from sys import stdin, stdout

def input():
	return stdin.readline()

def prin(x):
	return stdout.write(str(x) + '\n')
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	mod = n % x
	if mod == y:
		print(n)
	elif mod > y:
		n -= mod - y
		print(n)
	else:
		n -= mod
		if n % x == y:
			print(n)
		else:
			n -= x - y
			print(n)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	if a == y:
		print(n)
	elif a > y:
		diff = a - y
		j = n - diff
		print(j)
	elif a < y:
		b = a
		b += x - y
		k = n - b
		print(k)


m = int(input())
for i in range(0, m):
	(x, y, z) = list(map(int, input().split()))
	p = z % x
	if p >= y:
		print(z - (p - y))
	else:
		print(z + (y - p) - x)


t = int(input())
for T in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	rem = n % x
	div = n // x
	ans = 0
	ans = div * x + y
	if ans > n:
		ans = (div - 1) * x + y
	print(ans)


def remainder(x, y, n):
	a = n % x
	if a < y:
		n = n - a - x + y
	elif a > y:
		n = n - (a - y)
	else:
		n = n
	return n
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	print(remainder(x, y, n))


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	(x, y, n) = rl()
	r = n % x
	if r >= y:
		print(n - (r - y))
	else:
		print(n - (r - y) - x)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


n = int(input())
for _ in range(n):
	(a, b, c) = map(int, input().split())
	if c % a == b:
		print(c)
	else:
		k = c % a
		if b < k:
			print(c - k + b)
		else:
			print(c - k - a + b)


t = int(input())
ans = []
while t:
	(x, y, n) = map(int, input().split())
	div = int(n / x)
	res = int(div * x) + y
	if res > n:
		div -= 1
	ans.append(div * x + y)
	t -= 1
for i in range(len(ans)):
	print(ans[i])


_f = lambda : map(int, input().split())
for i in range(int(input())):
	(x, y, n) = _f()
	d = n // x
	if n < x:
		print(y)
	elif n % x < y:
		print((d - 1) * x + y)
	else:
		print(d * x + y)


for _ in range(int(input())):
	(x, y, n) = [int(x) for x in input().split()]
	k = n - (n - y) % x
	print(k)


import sys
from sys import stdin
from math import factorial

def neo():
	return map(int, input().split())

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(x, y, n) = neo()
	t = n // x
	if x * t + y > n:
		print(x * (t - 1) + y)
	else:
		print(x * t + y)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from bisect import bisect, bisect_right, bisect_left

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	(x, y, n) = get_tuple()
	return (n - y) // x * x + y

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	if s % n == k:
		print(s)
	else:
		c = s % n
		ans = s - c + k
		if ans > s:
			ans -= n
		print(ans)


import math as m
t = int(input())
for _ in range(t):
	(x, y, m) = map(int, input().split())
	a = m // x
	b = m % x
	if y == b:
		print(m)
	elif y < b:
		print(max(0, a * x + y))
	else:
		print(max(0, (a - 1) * x + y))


import os
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('in.txt', 'r')
	outF = open('out.txt', 'w')

def ins(r):
	return list(map(int, r.split(' ')))

def inputT():
	if is_dev:
		return inF.readline()
	else:
		return input()

def printT(data):
	if is_dev:
		return outF.write(str(data) + '\n')
	else:
		return print(data)
for _ in range(int(inputT())):
	(x, y, n) = ins(inputT())
	remainder_of_n = n // x * x + y
	if remainder_of_n <= n:
		printT(remainder_of_n)
	else:
		printT(remainder_of_n - x)
if is_dev:
	outF.close()
	print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())


import math
from collections import deque
from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	print((n - y) // x * x + y)


import math

def main():
	t = Iint()
	for _ in range(t):
		(x, y, n) = Imap()
		a = x * (n // x) + y
		if a > n:
			a -= x
		print(a)
FIO = True

def I():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if FIO:
	from io import BytesIO, IOBase
	import sys
	import os
en = enumerate
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t > 0:
	t -= 1
	(x, y, n) = map(int, input().split())
	z = int(n / x)
	while True:
		k = z * x + y
		if k < n + 1:
			print(k)
			break
		z -= 1


t = int(input())
ans = []
for i in range(t):
	(x, y, n) = map(int, input().split())
	ns = (n - y) // x * x + y
	ans.append(ns)
for el in ans:
	print(el)


N = int(input())
for _ in range(N):
	(x, y, n) = [int(x) for x in input().strip().split(' ')]
	s = n % x
	if n % x == y:
		pass
	else:
		if s > y:
			val = s - y
		else:
			val = abs(x - y) + s
		n = n - val
	print(n)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	ans = 0
	a = (n - y) % x
	print(n - a)

def func(n, m):
	if n == 1:
		return m
	elif n <= 0:
		return 1
	elif n % 6 == 0:
		return min(func(n // 6, m + 1), func(2 * n, m + 1))


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	rem = n % x
	if rem == y:
		print(n)
		continue
	if rem > y:
		print(n - (rem - y))
		continue
	ans = n - rem
	ans = ans - (x - y)
	if ans < 0:
		print(0)
		continue
	print(ans)


t = int(input())
for _ in range(t):
	[x, y, n] = [int(x) for x in input().split()]
	eq = n - n % x
	if eq + y <= n:
		print(eq + y)
	else:
		print(eq - (x - y))


cnt = int(input())
for _ in range(cnt):
	(x, y, n) = list(map(int, input().split()))
	kalan = n % x
	if kalan > y:
		kalan = kalan - y
		n = n - kalan
	elif kalan < y:
		kalan = kalan + x - y
		n = n - kalan
	print(n)


import bisect
import sys
import math
input = sys.stdin.readline
import functools
from collections import defaultdict

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))

def solve(case):
	[x, y, n] = inlt()
	res = n // x * x + y
	if res > n:
		res -= x
	return res
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)
	print(str(res))


from sys import stdin, stdout

def input():
	return stdin.readline().strip()

def ans(x, y, n):
	gap = ((n - y) % x + x) % x
	return n - gap
T = int(input())
for _ in range(T):
	(x, y, n) = input().split(' ')
	x = int(x)
	y = int(y)
	n = int(n)
	print(ans(x, y, n))


t = int(input())
i = 0
for i in range(0, t):
	(x, y, n) = [int(x) for x in input().split()]
	ans = 0
	j = 0
	if n - n % x + y <= n:
		ans = n - n % x + y
	else:
		ans = n - n % x - (x - y)
	print(ans)


t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	(x, y, n) = [int(i) for i in input().split()]
	print((n - y) // x * x + y)


a = int(input())
for i in range(a):
	(x, y, z) = input().split(' ')
	x = int(x)
	y = int(y)
	z = int(z)
	o = z - z % x + y
	p = z - z % x - (x - y)
	if o <= z:
		print(o)
	else:
		print(p)


t = int(input())
for cases in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	if n % x == y:
		print(n)
	else:
		if y - n % x < 0:
			k = n + y - n % x
		else:
			k = n + y - n % x - x
		if k >= 0:
			print(k)
		else:
			print(0)


def ninja(x, y, n):
	k = n % x
	if k == y:
		return n
	elif k > y:
		return n - (k - y)
	else:
		return n - k - (x - y)
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	print(ninja(x, y, n))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(x, y, n) = map(int, sys.stdin.readline().split())
	if n > x:
		if n % x > y:
			k = n - (n % x - y)
			print(k)
		elif n % x == y:
			print(n)
		elif n % x < y:
			n -= n % x
			k = n - (x - y)
			print(k)
	elif x == n and y == 0:
		print(n)
	else:
		k = y
		print(k)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if True:
		while True:
			break
		val = n // x
		temp = val * x + y
		if temp > n:
			val -= 1
			print(val * x + y)
		else:
			print(val * x + y)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
		continue
	if n < x:
		print(y)
		continue
	val = n % x
	if val > y:
		n -= abs(val - y)
		print(n)
		continue
	n -= val
	n -= abs(x - y)
	print(n)


t = int(input())
for tt in range(t):
	xyn = list(map(int, input().split()))
	s = int(xyn[2] / xyn[0]) * xyn[0]
	if xyn[2] - s < xyn[1]:
		s -= xyn[0]
	print(s + xyn[1])


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	(x, y, n) = rl()
	s = n // x
	if x * s + y <= n:
		print(x * s + y)
	else:
		print(x * (s - 1) + y)


def solve():
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x + (y - x))
T = 1
T = int(input())
for _ in range(1, T + 1):
	solve()


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n % x
	d = y - a
	if d <= 0:
		n = n + d
	else:
		n = n - x
		n = n + d
	print(n)


def getMinus(src, tar, x):
	if src == tar:
		return 0
	if src > tar:
		return src - tar
	return src + (x - tar)

def getMNum(x, y, n):
	temp = n % x
	return n - getMinus(temp, y, x)

def rmain():
	q = int(input())
	for _ in range(q):
		(x, y, n) = list(map(int, input().split()))
		print(getMNum(x, y, n))
rmain()


import io
import os
from sys import stdout, stdin
input = stdin.readline
for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n // x
	b = a * x
	c = n % x
	if c >= y:
		print(b + y)
	else:
		print(b + y - x)


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	print(str((n - y) // x * x + y))
	t -= 1


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
rli = lambda : map(int, stdin.readline().split())
rlf = lambda : map(float, stdin.readline().split())
(INF, NINF) = (float('inf'), float('-inf'))

def main():
	T = int(rl())
	for _ in range(T):
		(x, y, n) = rli()
		(q, r) = divmod(n, x)
		if y > r:
			print(n - (x - (y - r)))
		else:
			print(n - (r - y))
	stdout.close()
main()


answer = []
for i in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	if n - n % x + y <= n:
		answer.append(str(n - n % x + y))
	else:
		answer.append(str(n - n % x - (x - y)))
print('\n'.join(answer))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	num1 = n % x
	if num1 == y:
		k = n
	elif num1 > y:
		k = n - (num1 - y)
	else:
		k = n - num1 - x + y
	print(k)


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	(x, y, n) = map(int, stdin.readline().split())
	temp = n % x
	if temp >= y:
		ans = n - (temp - y)
	else:
		ans = n - temp
		ans -= x - y
	print(ans)


import math
T = int(input())
for _ in range(T):
	(x, y, n) = map(int, input().split())
	A = n // x * x
	if A + y <= n:
		A = A + y
	else:
		A = A - x + y
	print(A)


from sys import stdin
input = lambda : stdin.readline().rstrip('\r\n')
from collections import deque as que
from collections import defaultdict as vector
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
Testcase = inin()
for _ in range(Testcase):
	(x, y, n) = inar()
	a = n // x * x + y
	if a > n:
		a -= x
	print(a)


T = int(input())
for t in range(1, T + 1):
	string = input().split()
	x = int(string[0])
	y = int(string[1])
	n = int(string[2])
	print((n - y) // x * x + y)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = 0
	n1 = n
	while True:
		d = n // x
		exeans = x * d + y
		if exeans <= n1:
			ans = exeans
			break
		else:
			n = x * (d - 1)
	print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
t = 1
t = int(input())
for _ in range(t):
	(x, y, n) = l()
	if n % x >= y:
		print(n - n % x + y)
	else:
		print(max(y, n - x - n % x + y))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(x, y, n) = Ri()
	rem = n % x
	if rem == y:
		print(n)
	elif rem > y:
		dif = rem - y
		n -= dif
		print(n)
	else:
		n -= rem
		n -= x - y
		print(n)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	f = n % x
	if f == y:
		print(n)
	elif f > y:
		d = f - y
		print(n - d)
	else:
		g = n - f - x
		print(g + y)


num = int(input())
result = []
for i in range(num):
	(x, y, n) = map(int, input().split(' '))
	if n % x == y:
		result.append(n)
	elif n % x < y:
		result.append(n - x - (n % x - y))
	elif n % x > y:
		result.append(n - (n % x - y))
for i in result:
	print(i)


n1 = int(input())
for x in range(n1):
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	c = int(s[2])
	f = b % a
	i = c
	max = 0
	if f == 0:
		test = c % a
		max = c - test
	else:
		test = c % a
		if test == f:
			max = c
		elif test > f:
			max = c - (test - f)
		else:
			q = a - b
			max = c - test - q
	print(max)


t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	c = 0
	while n >= 0:
		c = n % x
		if c == y:
			print(n)
			break
		if c < y:
			n -= c + 1
		if c > y:
			n -= c - y


T = int(input())
while T > 0:
	(x, y, n) = map(int, input().split())
	times = n // x
	left = n % x
	if left >= y:
		res = x * times + y
	else:
		res = x * (times - 1) + y
	print(res)
	T -= 1


def solve(x, y, n):
	if n % x == y:
		return n
	rem = n % x
	if y < rem:
		return n - rem + y
	else:
		n = n - rem - 1
		rem = n % x
		return n - rem + y
test = int(input())
for i in range(test):
	arr = list(map(int, input().split()))
	print(solve(arr[0], arr[1], arr[2]))


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	d = n // x
	for j in range(d, -1, -1):
		g = j * x + y
		if g <= n:
			break
	print(g)


for test_case in range(int(input())):
	(x, y, n) = map(int, input().split())
	z = n % x
	if z > y:
		print(n - (z - y))
	elif z < y:
		m = x - 1
		print(n - z - 1 - (m - y))
	else:
		print(n)


t = int(input())
for _ in range(t):
	(x, y, n) = [int(a) for a in input().split()]
	a1 = y + n // x * x
	if a1 > n:
		a1 = y + (n // x - 1) * x
	print(a1)


import math
t = int(input())
f = [0 for i in range(1001000)]
for _ in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	k = math.floor((n - y) / x)
	print(k * x + y)


t = int(input())
numnum = 0
nummy = 0
for i in range(t):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	numnum = int(n / x)
	nummy = numnum * x + y
	if nummy > n:
		nummy = numnum * x - (x - y)
	print(nummy)
	continue


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	k = n
	num = n // x
	while True:
		if num * x + y <= n:
			print(num * x + y)
			break
		num -= 1


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	p = (c - b) // a
	q = p * a + b
	print(q)


def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = map(int, input().split())
		temp = n % x
		k = n - temp
		while k + y > n:
			k -= x
		print(k + y)
main()


n = int(input())
for x in range(n):
	(start, rem, end) = map(int, input().strip().split()[:3])
	if rem == 0:
		if end % start == 0:
			print(end)
		elif end - end % start + rem <= end:
			print(end - end % start + rem)
		else:
			k2 = (end - rem) // start
			k2 = k2 * start + rem
			print(k2)
	else:
		k1 = end - end % start + rem
		if k1 <= end:
			print(k1)
		else:
			k2 = (end - rem) // start
			k2 = k2 * start + rem
			print(k2)


import sys, math

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def get_array():
	l = list(map(int, input().split()))
	return l

def main():
	for tt in range(int(input())):
		l = get_array()
		(x, y, n) = (l[0], l[1], l[2])
		rem = n % x
		if rem == y:
			print(n)
		elif rem > y:
			diff = rem - y
			print(n - diff)
		else:
			diff = y - rem
			diff = x - diff
			print(n - diff)
main()


from sys import stdin
N = int(stdin.readline())
for case in range(N):
	(x, y, n) = [int(i) for i in stdin.readline().split()]
	d = n // x
	res = d * x
	if res + y > n:
		res = x * (d - 1)
	print(res + y)


Q = int(input())

def check(x, y, n):
	a = n % x
	if a == y:
		return n
	if a > y:
		return n - (a - y)
	else:
		return n - (a + x - y)
for i in range(Q):
	(x, y, n) = [int(c) for c in input().split()]
	print(check(x, y, n))


t = int(input())
for i in range(t):
	(x, y, z) = map(int, input().strip().split())
	a = int((z - y) / x)
	print(x * a + y)


pa = input()
p = int(pa)
while p > 0:
	p = p - 1
	na = input()
	n = na.split()
	x = int(n[0])
	y = int(n[1])
	z = int(n[2])
	if z % x == y:
		print(z)
	else:
		t = z % x
		if z - t + y <= z:
			print(z - t + y)
		else:
			print(z - t - (x - y))


n = int(input())
for _ in range(n):
	(x, y, z) = list(map(int, input().split()))
	s = z % x
	if s - y < 0:
		c = y - s
		print(z + c - x)
	else:
		c = s - y
		print(z - c)


ans = []
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	i = n % x
	if i == y:
		ans.append(n)
	elif i > y:
		ans.append(n - i + y)
	else:
		ans.append(n - i - x + y)
print('\n'.join(map(str, ans)))


def solve(arr):
	x = arr[0]
	y = arr[1]
	n = arr[2]
	q = n // x
	if n >= q * x + y:
		return q * x + y
	else:
		return q * x - (x - y)
t = int(input())
arr = []
for i in range(t):
	arr.append(list(map(int, input().split())))
for i in range(t):
	print(solve(arr[i]))


t = int(input())
while t != 0:
	s = input().split(' ')
	x = int(s[0])
	y = int(s[1])
	n = int(s[2])
	r = n % x
	if r == y:
		print(n)
	elif r > y:
		print(n - (r - y))
	elif r < y:
		w = n - r
		print(w - (x - y))
	t -= 1


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	q = n // x
	r = n % x
	if r < y:
		q = q - 1
	ans = q * x + y
	if ans < 0:
		ans = 0
	print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	r = n % x
	if y == r:
		print(n)
	if y < r:
		print(max(0, n - r + y))
	if y > r:
		print(max(0, n - r - x + y))


INT_MAX = 10 ** 30 + 7
MOD = 10 ** 9 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]
for i in range(int(input())):
	(x, y, n) = INPUT()
	print((n - y) // x * x + y)


def solve(x, y, n):
	z = n // x
	ans = z * x + y
	if ans > n:
		while ans > n:
			ans -= x
	return ans
t = int(input())
for we in range(t):
	(x, y, n) = map(int, input().split())
	print(solve(x, y, n))


t = int(input())
for i in range(t):
	a = list(map(int, input().strip().split()))[:3]
	x = a[0]
	y = a[1]
	n = a[2]
	temp_n = n - y
	temp = temp_n % x
	print(n - temp)


T = int(input())
for i in range(T):
	(x, y, n) = list(map(int, input().split()))
	Max = n // x * x + y
	if Max <= n:
		print(Max)
	else:
		print(Max - x)


T = int(input())
while T:
	(x, y, n) = map(int, input().split())
	i = 1
	while i * y % x != y:
		i = i + 1
	z = i * y
	j = (n - z) // x
	z += x * j
	print(z)
	T = T - 1


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n // x * x
	if y == 0 and n < x:
		print(0)
		continue
	if n - a == y:
		print(n)
	elif n % x >= y:
		print(a + y)
	else:
		print(a - x + y)


t = int(input())
for i in range(t):
	val = str(input())
	arr = val.split(' ')
	x = int(arr[0])
	y = int(arr[1])
	n = int(arr[2])
	num = n - y
	rem = num % x
	if rem == 0:
		ans = num / x
		final_ans = n
	else:
		ans = (num - rem) / x
		final_ans = x * ans + y
	print(int(final_ans))


import sys
import threading

def get_numbers():
	return map(int, sys.stdin.readline().strip().split())

def find_path(graph, start, vis):
	vis[start] = 1
	if not vis[graph[start]]:
		find_path(graph, graph[start], vis)

def main():
	t = int(input())
	for i in range(t):
		(x, y, n) = get_numbers()
		if n % x == y:
			print(n)
		elif n % x < y:
			print(n - (n % x + (x - y)))
		else:
			print(n - n % x + y)
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()


I = lambda : list(map(int, input().split(' ')))
for _ in range(I()[0]):
	(x, y, n) = I()
	a = (n - y) // x
	k = a * x + y
	print(k)


import math

def solution():
	(x, y, n) = map(int, input().split())
	mod = n % x
	if mod >= y:
		ans = n - (mod - y)
	else:
		ans = n - (mod + (x - y))
	print(ans)
for _ in range(int(input())):
	solution()


import sys
input = sys.stdin.readline

def solve(x, y, n):
	if n % x == y:
		return n
	elif n % x > y:
		return n - (n % x - y)
	else:
		return solve(x, y, n - n % x - 1)
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	print(solve(x, y, n))


t = int(input())
for i in range(t):
	xyn = list(map(int, input().split()))
	x = xyn[0]
	y = xyn[1]
	n = xyn[2]
	ans = 0
	if n - n // x * x >= y:
		ans = x * (n // x) + y
		print(ans)
	else:
		ans = x * (n // x - 1) + y
		print(ans)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	(x, y, n) = read_ints()
	ans = n // x * x + y
	if ans > n:
		ans -= x
	print(ans)


try:
	for t in [*open(0)][1:]:
		(x, y, n) = map(int, t.split())
		print(n - (n - y) % x)
except:
	pass


n = int(input())
for i in range(n):
	(x, y, n) = map(int, input().split())
	if n < x and y == 0:
		print(0)
	elif n < x and y == 1:
		print(1)
	elif n % x == y:
		print(n)
	elif x == 2 and y == 1 and (n == 1):
		print(1)
	elif n % x < y:
		print(n - (n % x + (x - y)))
	else:
		print(n - (n % x - y))


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	p = n % x - y
	ans = n - p
	if p < 0:
		ans -= x
	print(ans)


from sys import stdin
n = int(stdin.readline().rstrip())
for _ in range(n):
	(a, b, c) = map(int, stdin.readline().rstrip().split(' '))
	check = c // a
	if c % a == b:
		print(c)
	elif b == 0:
		print(check * a)
	elif check * a + b <= c:
		print(check * a + b)
	else:
		print((check - 1) * a + b)


testcase = int(input())
for i in range(testcase):
	(x, y, n) = map(int, input().split())
	count = n // x
	answer = x * count + y
	if answer > n:
		answer -= x
	print(answer)


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	max = n // x * x
	min = n % x
	if y > min:
		print(max - (x - y))
	else:
		print(max + y)


from math import *
t = int(input())
while t > 0:
	ip = [int(x) for x in input().split()]
	x = ip[0]
	y = ip[1]
	n = ip[2]
	z = n % x
	if z >= y:
		print(n - (z - y))
	else:
		print(n - x + (y - z))
	t -= 1


import statistics
import math
import datetime
from collections import Counter
import itertools

def func(xx, yy):
	pass

def main():
	for _ in range(int(input())):
		(x, y, n) = map(int, input().split())
		if n - n % x + y <= n:
			print(n - n % x + y)
		else:
			print(n - n % x - (x - y))
main()


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(x, y, n):
	m = n // x
	r = m * x + y
	if r > n:
		r -= x
	assert r % x == y
	return r
for i in tests():
	(x, y, n) = arr_in()
	out(solve(x, y, n))


def solve():
	global X, Y, N
	M = N % X
	if M < Y:
		return int(N / X) * X - (X - Y)
	return N - (M - Y)
import os
for _ in range(int(input())):
	(X, Y, N) = map(int, input().split())
	sol = solve()
	print(sol)


import math
t = int(input())
for a in range(t):
	(x, y, n) = map(int, input().split())
	maximum = n // x * x
	k = y + maximum
	if k <= n or k == n:
		print(k)
	elif k >= n:
		print(k - x)


_MULTITEST = True

def solve():
	(x, y, n) = map(int, input().split())
	k = n // x * x + y
	if k > n:
		k -= x
	print(k)
t = int(input()) if _MULTITEST else 1
for tt in range(t):
	solve()


output = []
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	remainder = n % x
	if remainder < y:
		output.append(n - remainder - (x - y))
	else:
		output.append(n - (remainder - y))
print(*output, sep='\n')


for test in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	div = (n - y) // x
	num = x * div + y
	print(num)


import sys
inpu = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	a = n % x
	b = y - a
	v = n + b
	if v > n:
		v = v - x
	print(v)


for result in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = n // x * x + y
	if ans > n:
		ans = ans - x
	print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = 1
	c = 1
	c = n // x
	a = c * x
	if a + y > n:
		a = a - x
	a += y
	print(a)


t = int(input())
for i in range(t):
	l = [int(z) for z in input().split()]
	p = int(l[2] / l[0]) * l[0]
	if p + l[1] > l[2]:
		print(p - l[0] + l[1])
	else:
		print(p + l[1])


z = int(input())
for h in range(z):
	(x, y, n) = map(int, input().split())
	if x > n:
		print(y)
	else:
		m = n % x
		if y <= m:
			ans = n - (m - y)
		else:
			ans = n - m - (x - y)
		print(ans)


import sys

class ARequiredRemainder:

	def solve(self, tc=0):
		for _ in range(int(input())):
			(x, y, n) = [int(_) for _ in input().split()]
			ans = n - n % x + y
			print(ans if ans <= n else ans - x)
solver = ARequiredRemainder()
input = sys.stdin.readline
solver.solve()


xynl = [list(map(int, input().split())) for _ in range(int(input()))]
for xyn in xynl:
	(x, y, n) = xyn
	print(n - n % x + y if n % x >= y else n - n % x + y - x)


import math
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	d = math.floor((n - y) / x)
	print(x * d + y)


test = int(input())
while test:
	test -= 1
	(x, y, n) = map(int, input().split())
	if n % x == y:
		ans = n
	elif n % x < y:
		ans = n - n % x - (x - y)
	elif n % x > y:
		ans = n - (n % x - y)
	print(ans)


t = int(input())
while t:
	t -= 1
	(x, y, n) = [int(x) for x in input().split(' ')]
	a = n // x
	while 1:
		if x * a + y <= n:
			print(x * a + y)
			break
		else:
			a -= 1


t = int(input())
for ts in range(t):
	(x, y, n) = [int(i) for i in input().split()]
	sol = n - n % x + y
	if sol > n:
		sol -= x
	print(sol)


from sys import stdin

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(x, y, n) = [int(x) for x in inp().split()]
	k = n - n % x
	if k + y > n:
		k -= x
		print(k + y)
	else:
		print(k + y)


import math as m
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	z = n // x * x
	if z + y > n:
		print(z - abs(x - y))
	else:
		print(y + z)


t = int(input())
for i in range(t):
	(x, y, k) = map(int, input().split())
	a = y % x
	c = x - a
	b = k % x
	if b < y:
		print(k - b - c)
	else:
		print(k + y - b)


test = int(input())
for i in range(test):
	(x, y, n) = [int(i) for i in input().split()]
	k = n // x
	if n % x == y:
		print(n)
	elif x * k + y > n:
		print(x * k - (x - y))
	else:
		print(x * k + y)


test = int(input())
for _ in range(test):
	(x, y, k) = map(int, input().split(' '))
	value = k - y
	another = value % x
	print(k - another)


t = int(input())
while t > 0:
	(x, y, n) = map(int, input().split())
	mod = n % x
	if mod == y:
		print(n)
	elif mod > y:
		print(n - (mod - y))
	else:
		val = y - mod
		n = n + val - x
		print(n)
	t -= 1


def sol(x, y, n):
	q = n // x
	r = n % x
	if x * q + y <= n:
		print(x * q + y)
	else:
		print(x * (q - 1) + y)
k = int(input())
for i in range(k):
	(x, y, n) = list(map(int, input().split(' ')))
	sol(x, y, n)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().strip().split())
	if n % x == y:
		ans = n
	elif n % x > y:
		ans = n - (n % x - y)
	elif n % x < y:
		ans = n - n % x - (x - y) % x
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, k) = list((int(x) for x in input().split()))
	c = k - b
	rem = c // a
	print(rem * a + b)


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, stdin.readline().split())
	temp = n % x
	if temp >= y:
		print(n - (temp - y))
	else:
		print(n - (x - (y - temp)))


def read_array():
	x = []
	x1 = []
	x = input()
	x = x.split(' ')
	for r in range(len(x)):
		x1.append(int(x[r]))
	return x1
res = []
r = int(input())
for m in range(r):
	p = read_array()
	x = p[0]
	y = p[1]
	n = p[2]
	l = n % x
	k = n
	if l == y:
		res.append(n)
	elif l < 0:
		res.append(0)
	elif l > y:
		k = n - (l - y)
		res.append(k)
	elif l < y:
		k = n - l - (x - y)
		res.append(k)
for v in res:
	print(v)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	k = max(0, n - y)
	p = k // x
	print(x * p + y)


t = int(input())
for test in range(t):
	(x, y, n) = [int(x) for x in input().split()]
	z = n % x
	req = y - z
	if req <= 0:
		ans = n - abs(req)
	else:
		ans = n - x + abs(req)
	print(ans)


for i in range(int(input())):
	a = list(map(int, input().split(' ')))
	print(a[2] - (a[2] - a[1]) % a[0])


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(x, y, n) = get_ints()
	q = n // x
	r = n % x
	if r == y:
		print(n)
	elif y > r:
		print(q * x - (x - y))
	else:
		print(n - r + y)


def solution(x, y, n):
	if n % x == y:
		return n
	if n % x > y:
		return n - (n % x - y)
	else:
		n -= n % x + 1
		return n - (n % x - y)
	return 0
tc = int(input())
while tc > 0:
	(x, y, n) = map(int, input().split())
	print(solution(x, y, n))
	tc -= 1


T = int(input())
for t in range(T):
	(x, y, N) = [int(i) for i in input().split()]
	m = N % x - y
	if m < 0:
		m += x
	print(N - m)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	(x, y, n) = MI()
	if n % x == y:
		print(n)
	elif n % x > y:
		print(n - n % x + y)
	else:
		print(n - x + y - n % x)


for i in [*open(0)][1:]:
	(x, y, n) = map(int, i.split())
	if n % x == y:
		print(n)
	elif n % x > y:
		print(n - (n % x - y))
	else:
		print(n - x + abs(y - n % x))


import sys
from math import sqrt
input = sys.stdin.readline

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	t = inp()
	for l in range(t):
		(x, y, n) = invr()
		mod = n % x
		if y <= mod:
			n -= mod - y
		else:
			n -= mod + (x - y)
		print(n)
main()


from math import ceil

def codeforces_round():
	for i in range(int(input())):
		x = list(map(int, input().split()))
		a = x[2] // x[0]
		while a * x[0] + x[1] > x[2]:
			a -= 1
		print(a * x[0] + x[1])
codeforces_round()


import math, string, itertools, operator, fractions, heapq, collections, re, array, bisect, sys, functools

def solve(line):
	(x, y, n) = map(int, line.split())
	return n - (n - y) % x
T = int(sys.stdin.readline())
t = 0
while True:
	line = sys.stdin.readline().rstrip()
	if not line:
		break
	print(solve(line))
	t += 1


import sys, os, time, json, random, math
t = int(input())
res = []
for i in range(t):
	(x, y, n) = [int(_) for _ in input().split()]
	if n // x * x + y > n:
		res.append((n // x - 1) * x + y)
	else:
		res.append(n // x * x + y)
for r in res:
	print(r)


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	mult = (n - y) // x
	print(mult * x + y)
	t -= 1


def main():
	t = int(input())
	for i in range(t):
		m = list(map(int, input().split()))
		(x, y, n) = (m[0], m[1], m[2])
		if y - n % x > 0:
			print(n - n % x + y - x)
		else:
			print(n - n % x + y)
main()


for _ in range(int(input())):
	(q, r, n) = map(int, input().split())
	x = n // q
	k = int(x * q + r)
	while k > n:
		x = x - 1
		k = int(x * q + r)
	print(k)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	p = n % x
	m = n - abs(y - p)
	if m % x == y:
		print(m)
	elif (n - (x - abs(y - p))) % x == y:
		print(n - (x - abs(y - p)))


def solve():
	(x, y, n) = [int(x) for x in input().split()]
	k = y
	m = int((n - x) / x)
	k += x * m
	while k + x <= n:
		k += x
	return k
T = int(input())
for case in range(T):
	print(solve())


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n // x
	b = x * a
	b += y
	while b > n:
		b -= x
	print(b)


import sys
from collections import defaultdict
name = sys.stdin.read()
jobGrid = []
isJob = True
row = []
grid = name.split('\n')
grid = grid[:-1]
number_of_cases = int(grid[0])
for i in range(number_of_cases):
	l = list(map(int, grid[i + 1].split()))
	mod = l[0]
	expected = l[1]
	start = l[2]
	startmod = start % mod
	diff = startmod - expected
	if diff < 0:
		diff = startmod + (mod - expected)
	print(start - diff)


case = int(input())
for i in range(0, case):
	(x, y, n) = [int(x) for x in input().split()]
	modDiff = n % x
	if modDiff >= y:
		minus = modDiff - y
	else:
		minus = modDiff + x - y
	answer = n - minus
	print(answer)


inc = int(input())
for i in range(inc):
	(x, y, n) = map(int, input().split())
	if n == 0:
		print('0')
	elif x >= n:
		if y == 0 and x == n:
			print(x)
		else:
			print(y)
	else:
		div = n // x
		mx = x * div + y
		while mx > n:
			div = div - 1
			mx = x * div + y
		print(mx)
quit()


for I in range(int(input())):
	(x, y, n) = map(int, input().split())
	temp = n // x
	if temp * x + y <= n:
		print(temp * x + y)
	else:
		print((temp - 1) * x + y)


import sys
inp = [i[:-1].split() for i in sys.stdin.readlines()[1:]]
for e in inp:
	(x, y, n) = (int(s) for s in e)
	if n % x == y:
		print(n)
	elif n % x < y:
		print(n - (x - abs(y - n % x)))
	else:
		print(n - abs(y - n % x))


from math import floor
t = int(input())
for x in range(t):
	[x, y, n] = list(map(int, input().strip().split(' ')))
	print(x * floor((n - y) / x) + y)


t = int(input())
for _ in range(t):
	ls = list(map(int, input().split()))
	x = ls[0]
	y = ls[1]
	n = ls[2]
	if n % x == y:
		print(n)
	else:
		p = n % x
		if y > p:
			print(n - x + (y - p))
		else:
			print(n - (p - y))


Q = int(input())
for i in range(Q):
	(a, b, n) = map(int, input().split())
	A = (n - b) // a
	print(A * a + b)


t = int(input())
while t:
	t = t - 1
	(x, y, n) = map(int, input().split())
	z = (n - y) // x
	print(z * x + y)


test = int(input())
for i in range(test):
	(x, y, k) = map(int, input().split())
	z = k % x
	ans = 0
	if z > y:
		ans = k - z + y
	elif z < y:
		ans = k - x + abs(z - y)
	else:
		ans = k
	print(ans)


T = int(input())
for I in range(0, T):
	M = input().split(' ')
	X = int(M[0])
	Y = int(M[1])
	N = int(M[2])
	print(int((N - Y) // X * X + Y))


def solve():
	(x, y, n) = map(int, input().split())
	r = n - y
	r = r // x * x
	print(r + y)
for i in range(int(input())):
	solve()


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	q = n // x
	s = q * x
	if s + y > n:
		q -= 1
		s = q * x
		print(s + y)
	else:
		print(s + y)


import math
import datetime
import collections
import statistics
import itertools

def is_prime(num):
	for i in range(2, int(math.sqrt(num)) + 1):
		if num % i == 0:
			return False
	return True

def input_list():
	ll = list(map(int, input().split(' ')))
	return ll
tc = int(input())
for _ in range(tc):
	(x, y, n) = map(int, input().split())
	if n % x == y:
		print(n)
	else:
		cc = (n - y) // x
		f = cc * x + y
		print(f)


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n < x:
		print(y)
	elif n % x == y:
		print(n)
	elif n % x == 0:
		n -= x
		print(n + y)
	elif n % x > y:
		print(n - (n % x - y))
	elif n % x < y:
		k = n % x
		n -= k
		n -= x
		print(n + y)


import sys
I = sys.stdin.readline
pr = sys.stdout.write

def main():
	for _ in range(int(I())):
		(x, y, n) = map(int, I().split())
		pr(f'{((n if n % x == y else n - x + (x + y - n % x) % x) if n >= x else y)}\n')
main()


t = input()
arr = []
for i in range(int(t)):
	arr.append(list(map(int, input().split())))
for j in range(int(t)):
	if arr[j][2] > arr[j][0]:
		if arr[j][2] % arr[j][0] == arr[j][1]:
			print(arr[j][2])
		elif arr[j][2] % arr[j][0] > arr[j][1]:
			print(arr[j][2] - (arr[j][2] % arr[j][0] - arr[j][1]))
		else:
			print(arr[j][2] - arr[j][0] + (arr[j][1] - arr[j][2] % arr[j][0]))
	elif arr[j][2] == arr[j][0] and arr[j][1] == 0:
		print(arr[j][2])
	else:
		print(arr[j][1])


from pprint import pprint
import sys
import math

def do():
	(x, y, k) = map(int, input().split())
	a = x * math.floor(k / x)
	a += y
	if a > k:
		a -= x
	print(a)
q = int(input())
for _ in range(q):
	do()


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	t1 = n // x
	t2 = t1 * x
	if y == 0:
		print(t2)
	else:
		a = x - y
		if y + t2 <= n:
			print(y + t2)
		else:
			print(t2 - a)


T = int(input())
for tc in range(T):
	(y, x, n) = map(int, input().split())
	if y == 0:
		ans = x * (n // x)
	else:
		ay = n // y
		if n - (y * ay + x) < 0:
			ay -= x // y
			if n - (y * ay + x) < 0:
				ay -= 1
		ans = y * ay + x
	print(ans)


for i in [*open(0)][1:]:
	(a, b, c) = map(int, i.split())
	print(c - (c - b) % a)


def res(x, y, n):
	k = n
	cnt = 0
	temp = k % x
	if temp < y:
		cnt = temp + (x - y)
	elif temp > y:
		cnt = temp - y
	print(k - cnt)
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	res(x, y, n)


def checker(x, y, n):
	q = (n - y) // x
	return q * x + y
for _ in range(int(input())):
	(X, Y, N) = [int(i) for i in input().split()]
	print(checker(X, Y, N))


for nt in range(int(input())):
	(x, y, n) = map(int, input().split())
	r = n % x
	if r == y:
		print(n)
		continue
	if y < r:
		print(n - (r - y))
		continue
	print(n - x + (y - r))


for _ in range(int(input())):
	(x, y, n) = tuple(map(int, input().split()))
	d = n % x
	if d == y:
		res = n
	elif d > y:
		d = d - y
		res = n - d
	else:
		n -= d
		res = n - (x - y)
	print(res)


t = int(input())
for i in range(t):
	xyn = list(map(int, input().split()))
	x = xyn[0]
	y = xyn[1]
	n = xyn[2]
	divided = n // x
	k = divided * x + y
	if k > n:
		k -= x
	print(k)


def eval(x, y, n):
	R = n % x
	ans = n - R + y
	if ans < 0:
		return 0
	elif ans > n:
		ans -= x
		return ans
	else:
		return ans
for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	print(eval(x, y, n))


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	(x, y, n) = arrIN()
	t = n // x * x
	if t + y > n:
		print(t - x + y)
	else:
		print(t + y)


try:
	k = int(input())
	for i in range(k):
		lis = list(map(int, input().split()))
		val = lis[2] // lis[0]
		if val * lis[0] + lis[1] <= lis[2]:
			print(val * lis[0] + lis[1])
		else:
			print((val - 1) * lis[0] + lis[1])
except Exception:
	pass


def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	(x, y, n) = map(int, input().split())
	z = n // x
	if y + z * x > n:
		print(z * x - (x - y))
		continue
	print(z * x + y)


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
t = int(input())
for _ in range(t):
	(x, y, n) = get_ints()
	t = n % x
	if t >= y:
		n -= t - y
	else:
		n -= t + (x - y)
	print(max(n, 0))


for t in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = n // x * x + y
	if ans > n:
		ans -= x
	print(max(ans, 0))


for _ in range(int(input())):
	(a, b, n) = list(map(int, input().split()))
	cur = n // a
	if cur * a + b > n:
		print((cur - 1) * a + b)
	elif cur * a + b == n:
		print(n)
	elif cur * a + b < n:
		print(cur * a + b)
	else:
		print(0)


T = int(input())
while T > 0:
	(x, y, n) = map(int, input().split())
	a = n // x
	b = n - a * x
	t = a
	while t > a + (b - y) / x:
		t = t - 1
	print(t * x + y)
	T = T - 1


for cases in range(int(input())):
	(x, y, n) = map(int, input().split())
	t = n // x
	if t * x + y > n:
		print((t - 1) * x + y)
	elif t * x + y == n:
		print(n)
	elif t * x + y < n:
		print(t * x + y)
	else:
		print(0)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	quo = n // x
	ans = quo * x + y
	if ans > n:
		ans -= x
	print(ans)


import sys, math
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math

def solve():
	(X, Y, N) = getInts()
	ans = N - N % X + Y % X
	while ans > N:
		ans -= X
	return ans
for _ in range(getInt()):
	print(solve())


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
from math import log, log2, sqrt, factorial, cos, tan, sin, radians, ceil, floor
import bisect
from decimal import *
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		(x, y, n) = mi()
		if y == 0:
			c = n // x
			print(x * c)
			continue
		n -= y
		c = n // x
		ans = c * x
		ans += y
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	if n < x:
		print(y)
		continue
	if n % x == y:
		print(n)
		continue
	r = n % x
	if r >= y:
		n -= r - y
	else:
		n = n - n % x
		n -= x - y
	print(n)


for _ in range(int(input())):
	(div, mod, n) = list(map(int, input().split()))
	a = n // div
	while a * div + mod > n:
		a -= 1
	print(a * div + mod)


def brute(x, y, n):
	result = 0
	for k in range(0, n + 1):
		if k % x == y:
			result = k
	return result

def fast(x, y, n):
	yp = n % x
	if yp == y:
		return n
	return n - (yp - y) % x

def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = [int(x) for x in input().split()]
		result = fast(x, y, n)
		print(result)

def randomTest():
	import random
	t = 100
	for i in range(1, t + 1):
		x = random.randint(2, 10)
		y = random.randint(0, x - 1)
		n = random.randint(y, 10)
		print(x, y, n)
		b = brute(x, y, n)
		f = fast(x, y, n)
		if b != f:
			print('broken!')
			print(b, f)
			return
main()


c = int(input())
t = 0
for t in range(c):
	(x, y, n) = map(int, input().split(' '))
	k = int((n - y) / x)
	print(k * x + y)


import sys
fin = sys.stdin.read().split('\n')
del fin[-1]
(amount, out) = (int(fin.pop(0)), [])
fin = [fin[i].split() for i in range(amount)]
for i in range(amount):
	fin[i] = [int(fin[i][x]) for x in range(3)]
for i in range(amount):
	out.append(str(fin[i][0] * ((fin[i][2] - fin[i][1]) // fin[i][0]) + fin[i][1]))
sys.stdout.write('\n'.join(out) + '\n')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(x, y, n) = map(int, input().split())
	ans = n % x - y
	print(n - ans if ans >= 0 else n - (x + ans))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(a, b, n) = list(map(int, input().split()))
		c = n % a
		if c >= b:
			yield (n - (c - b))
		else:
			yield (n - c - (a - b))
t = int(input())
ans = gift()
print(*ans, sep='\n')


a = int(input())
for i in range(a):
	(x, y, n) = map(int, input().split())
	d = (n - y) // x
	s = d * x + y
	print(s)


t = int(input())
for r in range(t):
	(x, y, n) = map(int, input().split())
	z = n // x
	v = z * x + y
	while v > n:
		z = z - 1
		v = z * x + y
	print(v)


t = int(input())
for i in range(t):
	(x, y, n) = input().split()
	x = int(x)
	y = int(y)
	n = int(n)
	d = n % x
	e = n // x
	if d == y:
		print(n)
	elif d < y:
		k = (e - 1) * x + y
		print(k)
	elif d > y:
		l = n - (d - y)
		print(l)


t = int(input())
i = 0
while i < t:
	(x, y, n) = input().split(' ')
	x = int(x)
	y = int(y)
	n = int(n)
	n = n - y
	print(n - n % x + y)
	i += 1


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	(x, y, n) = IP()
	a = n // x
	if x * a + y > n:
		a -= 1
		print(x * a + y)
	else:
		print(x * a + y)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().strip().split(' '))
	if n % x == y:
		print(n)
	else:
		c = n // x
		c1 = n % x
		if c1 < y:
			print((c - 1) * x + y)
		else:
			c2 = c1 - y
			print(n - c2)


num = int(input(''))
for i in range(num):
	nums = list(map(int, input('').split(' ')))
	x = nums[0]
	y = nums[1]
	n = nums[2]
	mainnum = n - y
	numberminus = mainnum % x
	ans = n - numberminus
	print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	div = n // x
	rem = n % x
	if y <= rem:
		print(n - rem + y)
	else:
		print(n - rem - x + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	q = n // x
	if x * q + y <= n:
		print(f'{x * q + y}')
	else:
		print(f'{x * (q - 1) + y}')


t = int(input())
for e in range(t):
	(x, y, z) = [int(a) for a in input().split()]
	div = (z - y) // x
	res = div * x + y
	print(res)


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
import statistics
from statistics import mode
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def most_frequent(List):
	occurence_count = Counter(List)
	return occurence_count.most_common(1)[0][0]

def most_common(List):
	return mode(List)

def createMatrix(rowCount, colCount, dataList):
	mat = []
	for i in range(rowCount):
		rowList = []
		for j in range(colCount):
			if dataList[j] not in mat:
				rowList.append(dataList[j])
		mat.append(rowList)
	return mat

def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
import collections

def minimalFilps1(bits):
	n = len(bits)
	flipsFromLeft = [0 for i in range(n)]
	flipsFromRight = [0 for i in range(n)]
	flips = 0
	for i in range(0, n, 1):
		if bits[i] == '1':
			flips = flips + 1
		flipsFromLeft[i] = flips
	flips = 0
	i = n - 1
	while i >= 0:
		if bits[i] == '0':
			flips = flips + 1
		i = i - 1
		flipsFromRight[i] = flips
	minFlips1 = sys.maxsize
	for i in range(1, n, 1):
		if flipsFromLeft[i - 1] + flipsFromRight[i] < minFlips1:
			minFlips1 = flipsFromLeft[i - 1] + flipsFromRight[i]
	return minFlips1

def minimalFilps(bits):
	n = len(bits)
	flipsFromLeft = [0 for i in range(n)]
	flipsFromRight = [0 for i in range(n)]
	flips = 0
	for i in range(0, n, 1):
		if bits[i] == '0':
			flips = flips + 1
		flipsFromLeft[i] = flips
	flips = 0
	i = n - 1
	while i >= 0:
		if bits[i] == '1':
			flips = flips + 1
		i = i - 1
		flipsFromRight[i] = flips
	minFlips = sys.maxsize
	for i in range(1, n, 1):
		if flipsFromLeft[i - 1] + flipsFromRight[i] < minFlips:
			minFlips = flipsFromLeft[i - 1] + flipsFromRight[i]
	return minFlips

def oddn(n):
	for i in range(2, n + 1):
		if i % 2 != 0 and n % i == 0:
			return i
	return 3

def memoized(*args):
	if args in stored_results:
		return stored_results[args]
	else:
		result = stored_results[args] = fn(*args)
		return result
	return memoized
import operator
for i in range(int(inp())):
	(x, y, n) = map(int, inp().split())
	a = (n - y) // x * x + y
	print(a)
open_list = ['(']
close_list = [')']

def check(myStr):
	stack = []
	for i in myStr:
		if i in open_list:
			stack.append(i)
		elif i in close_list:
			pos = close_list.index(i)
			if len(stack) > 0 and open_list[pos] == stack[len(stack) - 1]:
				stack.pop()
			else:
				return -1
	if len(stack) == 0:
		return 0
	else:
		return -1

def Balanced_Substring(s, n):
	ans = 0
	arr = [0] * (int(n / 2) + 1)
	d = 0
	for i in range(n):
		if s[i] == '(':
			d += 1
		else:
			if d == 1:
				j = 2
				while j <= n // 2 + 1 and arr[j] != 0:
					arr[j] = 0
			ans += 1
			ans += arr[d]
			arr[d] += 1
			d -= 1
	return ans


t = int(input())
for i in range(t):
	s = input().split(' ')
	for (j, x) in enumerate(s):
		s[j] = int(x)
	print((s[2] - s[1]) // s[0] * s[0] + s[1])


import sys
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
ttt = inp[ii]
ii += 1
for _ in range(ttt):
	(x, y, n) = inp[ii:ii + 3]
	ii += 3
	rem = y % x
	print((n - rem) // x * x + rem)


n = int(input())
for i in range(n):
	q = input().split()
	a = int(q[0])
	b = int(q[1])
	c = int(q[2])
	print((c - b) // a * a + b)


def Solve(x, y, n):
	rem = n % x
	if rem == y:
		return n
	if rem > y:
		return n - (rem - y)
	n -= rem + 1
	rem = n % x
	if rem == y:
		return n
	return n - (rem - y)
T = int(input())
for _ in range(T):
	(x, y, n) = map(int, input().split())
	print(Solve(x, y, n))


import math
t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	if y == 0:
		if n < x:
			print(0)
			continue
		elif n == x:
			print(n)
			continue
	p = n % x
	if p == y:
		print(n)
		continue
	elif p < y:
		print(n - p - x + y)
	else:
		print(n - p + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	ans = n // x * x + y
	i = 1
	while ans > n:
		ans = (n // x - 1) * x + y
		i += 1
	print(ans)


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	a = n // x
	k = a * x + y
	if k > n:
		print((a - 1) * x + y)
	else:
		print(a * x + y)


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	(x, y, n) = f()
	if n % x == y:
		print(n)
	elif n % x < y:
		print(n - n % x - x + y)
	else:
		print(n - n % x + y)


for testcase in range(int(input())):
	(x, y, n) = map(int, input().split())
	temp = n // x
	ans = temp * x + y
	if ans > n:
		ans -= x
	print(ans)


for i in range(int(input())):
	(a, b, k) = map(int, input().split())
	r = k % a
	if r == b:
		print(k)
	elif r < b:
		print(k - r - (a - b))
	else:
		print(k - (r - b))


def fun(x, y, n):
	q = n % x
	if q > y:
		return n - (q - y)
	elif q == y:
		return n
	else:
		return n - x + (y - q)
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	ans = fun(x, y, n)
	print(ans)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	k1 = n - y
	k2 = k1 // x
	ans = k2 * x + y
	print(int(ans))


t = int(input())
while t:
	t -= 1
	ip = input().split(' ')
	(x, y, n) = (int(ip[0]), int(ip[1]), int(ip[2]))
	if n % x < y:
		print(n - (n % x + (x - y)))
	else:
		print(n - (n % x - y))


t = int(input())
ans = []
for i in range(t):
	x = []
	(x, y, n) = [int(i) for i in input().split()]
	q = n % x
	if q == y:
		ans.append(n)
	elif q > y:
		ans.append(n - (q - y))
	else:
		ans.append(n - x + y - q)
for i in ans:
	print(i)


import math

class Solution:

	def possible(self, a, x, y, n):
		return a * x + y <= n

	def solve(self, x, y, n):
		(low, high) = (0, math.ceil(n / x) + 1)
		a = 0
		while low < high:
			mid = low + (high - low) // 2
			if self.possible(mid, x, y, n):
				low = mid + 1
				a = max(a, mid)
			else:
				high = mid
		return a * x + y
for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	ans = Solution().solve(x, y, n)
	print(ans)


def sample(x, y, n):
	z = n // x
	value = z * x + y
	while value > n:
		z = z - 1
		value = z * x + y
	return value
t = int(input())
for p in range(t):
	(x, y, n) = map(int, input().split())
	print(sample(x, y, n))


def task_A():
	t = int(input())
	for _ in range(t):
		(x, y, n) = map(int, input().split())
		add = n // x
		add_ostatok = n % x
		if y <= add_ostatok:
			print(add * x + y)
		else:
			print(add * x - x + y)

def main():
	task_A()
main()


g = int(input())
for i in range(g):
	g = input().split()
	g = [int(i) for i in g]
	l = (g[2] - g[1]) % g[0]
	print(g[2] - l)


for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	if x > n and y == 0:
		print(0)
	elif n % x == y:
		print(n)
	elif n % x > y:
		print(n - (n % x - y))
	elif n % x < y:
		print(n - (x - y + n % x))


cases = int(input())
for i in range(cases):
	(x, y, n) = [int(i) for i in input().split()]
	dis = abs(n % x - y)
	if n % x == y:
		print(n)
	elif (n + dis - x) % x == y:
		print(n + dis - x)
	else:
		for i in range(x):
			n -= dis
			dis = abs(n % x - y)
			if (n - dis) % x == y:
				print(n - dis)
				break


import sys

def main():
	t = int(input())
	for _ in range(t):
		(x, y, n) = list(map(int, input().split()))
		print((n - y) // x * x + y)
main()


loop = int(input())
while loop > 0:
	loop -= 1
	(x, y, n) = map(int, input().split())
	temp = n % x
	if temp == y:
		k = n
	elif temp < y:
		k = n - temp - (x - y)
	else:
		k = n - (temp - y)
	print(k)


from math import ceil, log, floor, sqrt
import math

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def find_k(x, y, n):
	return (n - y) // x * x + y
t = 1
t = int(input())
while t:
	t = t - 1
	(x, y, n) = map(int, input().split())
	print(find_k(x, y, n))


t = int(input())
for m in range(t):
	(e, y, n) = map(int, input().split())
	if n % e < y:
		print(n - e - n % e + y)
	else:
		print(n - n % e + y)


t = int(input())
answer = []
for a in range(t):
	line = input().split()
	x = int(line[0])
	y = int(line[1])
	n = int(line[2])
	if n - n % x + y <= n:
		answer.append(str(n - n % x + y))
	else:
		answer.append(str(n - n % x - (x - y)))
for b in answer:
	print(str(b))


for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	m = 0
	n -= y
	v = n // x
	print(x * v + y)


import sys

def rl():
	return sys.stdin.readline().strip()
T = int(rl())
for test in range(T):
	(x, y, n) = map(int, rl().split())
	MOD = n % x
	if MOD >= y:
		print(n - MOD + y)
	else:
		print(n - x - MOD + y)


def solve(x, y, n):
	t = n % x
	k = n - t + y
	if k > n:
		print(k - x)
	else:
		print(k)
tc = int(input())
while tc > 0:
	(a, b, c) = map(int, input().split())
	solve(a, b, c)
	tc -= 1


for ad in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	a = n % x
	if y <= a:
		print(n - a + y)
	else:
		print(n - a + y - x)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far
from math import *
for _ in range(int(input())):
	(x, y, n) = map(int, input().split())
	maxi = n // x * x
	rem = n % x
	if rem >= y:
		print(maxi + y)
	else:
		print(maxi - x + y)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(inin()):
		(x, y, n) = map(int, input().split())
		count = n // x
		if count * x + y <= n:
			print(count * x + y)
		else:
			print(count * x - (x - y))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	k = int(c / a)
	if k * a + b > c:
		k = k - 1
	print(k * a + b)


import sys
t = int(sys.stdin.readline().split()[0])
k = 0
for line in sys.stdin:
	x = int(line.split()[0])
	y = int(line.split()[1])
	n = int(line.split()[2])
	if n - n % x + y <= n:
		print(n - n % x + y)
	else:
		print(n - n % x - (x - y))


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	nn = int(x * (n // x))
	if nn + y <= n:
		print(nn + y)
	else:
		print(nn + y - x)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split(' '))
	rem = n % x
	if y == 0:
		if n < x:
			print(0)
			continue
		else:
			print(n // x * x)
			continue
	if rem == y:
		print(n)
	elif rem < y:
		val = (n // x - 1) * x + y
		print(val)
	else:
		print(n - (rem - y))


import io
import os
from collections import Counter, defaultdict, deque

def solve(X, Y, N):
	M = (N - Y) // X
	return X * M + Y
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(X, Y, N) = [int(x) for x in input().split()]
	ans = solve(X, Y, N)
	print(ans)


t = int(input())
while t != 0:
	(a, b, n) = map(int, input().split())
	x = int(n / a)
	y = int(x * a)
	z = int(y + b)
	if z > n:
		z -= a
	print(z)
	t -= 1


for _ in range(int(input())):
	(x, y, n) = list(map(int, input().split()))
	ans = y
	dif = n - ans
	dif %= x
	ans = n - dif
	print(ans)


p = 0
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	if n % x != y:
		p = (n - y) // x
		p *= x
		p += y
		print(p)
	else:
		print(n)


for _ in range(int(input())):
	(x, y, n) = (int(i) for i in input().split())
	ost = n % x
	if ost < y:
		n = n - ost - (x - y)
	elif ost > y:
		n = n - (ost - y)
	print(n)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(x, y, n) = I()
	if n <= y:
		print(n)
	else:
		an = n // x * x + y
		print(an if an <= n else an - x)


t = int(input())
while t > 0:
	array = list(map(int, input().split()))
	x = int(array[2] // array[0] * array[0] + array[1])
	if x > array[2]:
		x -= array[0]
	print(x)
	t -= 1


def fun(x, y, n):
	t = n % x
	if t == y:
		print(n)
	elif t < y:
		print(n - (x - (y - t)))
	elif t > y:
		print(n - (t - y))
for i in range(int(input())):
	(x, y, n) = map(int, input().split())
	fun(x, y, n)


import sys, math
t = int(sys.stdin.readline())
for _ in range(t):
	(x, y, n) = map(int, sys.stdin.readline().split())
	if n < x:
		print(y)
	else:
		print(int((n - y) / x) * x + y)


t = int(input())
while t > 0:
	(a, b, c) = [int(n) for n in input().split()]
	d = b + int(c / a) * a
	if d > c:
		d -= a
	print(int(d), end='\n')
	t -= 1


import math
t = int(input())
for i in range(t):
	for (x, y, n) in [input().split()]:
		(x, y, n) = (int(x), int(y), int(n))
		self = x * math.floor(n / x) + y
		if self > n:
			print(self - x)
		else:
			print(self)


def list_input():
	return list(map(int, input().split()))

def multiple_input():
	return map(int, input().split())
for _ in range(int(input())):
	(x, y, n) = multiple_input()
	first = x + y
	if first > n:
		ans = y
	else:
		n -= first
		ans = n // x * x
		ans += first
	print(ans)


for _ in range(int(input())):
	a = [int(x) for x in input().split()]
	print(a[2] - (a[2] - a[1]) % a[0])


test_cases = int(input())
for i in range(test_cases):
	(x, y, n) = [int(i) for i in input().split()]
	if n % x >= y:
		print(n - (n % x - y))
	else:
		print(n - n % x - (x - y))


def solution1():
	for tangocharlie in range(int(input())):
		(xx, yy, nn) = map(int, input().split())
		p = nn // xx
		k = p * xx + yy
		while k > nn:
			p -= 1
			k = p * xx + yy
		print(k)

def solution2():
	for tangocharlie in range(int(input())):
		nnn = int(input())
		apple = 5
		banana = 10
		orange = apple + banana
		answer = 0
		while nnn > 1:
			if nnn % 6 == 0:
				answer += 1
				nnn = nnn // 6
			elif nnn % 3 == 0 and nnn % 2 != 0:
				answer += 1
				nnn *= 2
			else:
				answer = -1
				break
		print(answer)

def solution3():
	for tangocharlie in range(int(input())):
		number = int(input())
		sunlight = list(input())
		opnn = wrong = 0
		for i in sunlight:
			if i == '(':
				opnn += 1
			else:
				opnn -= 1
			if opnn < 0:
				wrong += 1
				opnn = 0
		print(wrong)

def solution4():
	for tangocharlie in range(int(input())):
		(n, k) = map(int, input().split())
		abra_ka_dabra = sorted(list(map(int, input().split())))
		abra_ka_dabra1 = []
		for i in abra_ka_dabra:
			if i % k != 0:
				abra_ka_dabra1.append(k - i % k)
		if len(abra_ka_dabra1) == 0:
			print(0)
			continue
		abra_ka_dabra1.sort()
		ans = abra_ka_dabra1[0]
		curr = abra_ka_dabra1[0]
		for i in range(1, len(abra_ka_dabra1)):
			if abra_ka_dabra1[i] != abra_ka_dabra1[i - 1]:
				curr = abra_ka_dabra1[i]
			else:
				curr += k
			ans = max(ans, curr)
		print(ans + 1)
solution1()


a = int(input())
l = []
for i in range(a):
	(x, y, n) = str(input()).split(' ')
	x = int(x)
	y = int(y)
	n = int(n)
	a1 = n // x
	a1 = a1 * x
	a2 = a1 + y
	a3 = a1 + y - x
	if a2 > n:
		l.append(a3)
	else:
		l.append(a2)
for j in l:
	print(j)


t = int(input())
while t > 0:
	(x, y, n) = list(map(int, input().split()))
	r = n % x
	ans = n - r + y
	if y > r:
		ans = ans - x
	print(ans)
	t = t - 1


def solve(x, y, n):
	r = (n - y) // x
	k = r * x + y
	return k
t = int(input())
for i in range(t):
	(x, y, n) = [int(x) for x in input().split(' ')]
	print(solve(x, y, n))


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	for _ in range(ii()):
		(x, y, n) = mi()
		x1 = n // x
		x3 = x1 * x + y
		ans = (x1 - 1) * x + y
		if x3 <= n:
			ans = x3
		print(ans)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	k = n // x
	aa = x * k
	h = True
	ans = 0
	while h:
		if aa + y <= n:
			h = False
			ans = aa + y
		else:
			aa -= x
	print(ans)


t = int(input())
for caseNr in range(1, t + 1):
	array = list(map(int, input().split()))
	x = array[0]
	y = array[1]
	n = array[2]
	k = x * ((n - y) // x) + y
	print(k)


t = int(input())
for i in range(t):
	(q, r, num) = map(int, input().split())
	effectiveq = (num - r) // q
	num = effectiveq * q + r
	print(num)


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	res = n - (n % a + (a - b)) % a
	print(res)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(x, y, n) = map(int, input().split())
	k = (n - y) // x
	print(k * x + y)


t = int(input())
for _ in range(t):
	(x, y, n) = map(int, input().split())
	norig = n
	nx = n % x
	n -= nx
	if n + y <= norig:
		print(n + y)
	else:
		print(n - x + y)


from math import floor
T = int(input())
for t in range(T):
	(x, y, n) = [int(x) for x in input().split()]
	print(floor((n - y) / x) * x + y)


cas = int(input())

def solve():
	(x, y, n) = [int(x) for x in input().split(' ')]
	r = n % x
	if r == y:
		print(n)
		return
	if r > y:
		print(n - (r - y))
	if r < y:
		print(n - r - x + y)
while cas > 0:
	cas -= 1
	solve()


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(x, y, n) = map(int, input().split())
	print((n - y) // x * x + y)


def solve(lt):
	x = lt[0]
	y = lt[1]
	k = lt[2]
	i = k // x
	if i * x + y > k:
		return (i - 1) * x + y
	else:
		return i * x + y

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))
n = inp()
in_lst = []
for i in range(n):
	in_lst.append(inlt())
for i in range(n):
	print(solve(in_lst[i]))


def driver():
	t = int(input())
	for i in range(t):
		print(solution())

def solution():
	(x, y, n) = [int(x) for x in input().split()]
	m = n % x
	if m == y:
		return n
	elif m > y:
		return n - (m - y)
	else:
		return n - m - x + y
driver()


for _ in range(int(input())):
	(x, y, n) = [int(x) for x in input().split()]
	ans = y
	t2 = n // x
	if t2 * x + y <= n:
		print(t2 * x + y)
	else:
		print(max(t2 - 1, 0) * x + y)


t = int(input())
while t:
	(x, y, n) = map(int, input().split())
	z1 = n // x
	z2 = z1 - 1
	ans1 = z1 * x + y
	ans2 = z2 * x + y
	if ans1 % x == y and ans1 <= n:
		print(ans1)
	else:
		print(ans2)
	t = t - 1


t = int(input())
for t_i in range(t):
	(x, y, n) = map(int, input().split())
	x_mul = n // x * x
	if x_mul + y > n:
		x_mul -= x
	k = x_mul + y
	print(k)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
test = inp()
for i in range(0, test):
	inpu = inlt()
	x = inpu[0]
	y = inpu[1]
	n = inpu[2]
	rem1 = n % x
	if rem1 < y:
		output = n - rem1 - x + y
	elif rem1 > y:
		output = n - rem1 + y
	elif rem1 == y:
		output = n
	print(output)


import sys
readline = sys.stdin.readline
N = int(readline())
for _ in range(N):
	(x, y, n) = map(int, readline().split())
	print(x * ((n - y) // x) + y)


def func(x, y, n):
	rem = n % x
	if rem < y:
		ans = n - rem - (x - y)
	else:
		ans = n - (rem - y)
	print(ans)
t = int(input())
for i in range(t):
	(x, y, n) = map(int, input().split())
	func(x, y, n)


for _ in range(0, int(input())):
	mylist = list(map(int, input().split()))[:3]
	x = mylist[0]
	y = mylist[1]
	n = mylist[2]
	someval = (n - y) % x
	print(n - someval)


import sys

def in_int():
	return int(sys.stdin.readline())

def in_str():
	return sys.stdin.readline().rstrip()

def in_map_int():
	return map(int, sys.stdin.readline().split())

def in_arr_int():
	return list(map(int, sys.stdin.readline().split()))

def in_arr_str():
	return sys.stdin.readline().split()

def is_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			return True
	return False

def solve(x, y, n):
	a = n - n % x + y
	b = n - n % x + y - x
	return a if a <= n else b

def main():
	t = in_int()
	for _ in range(t):
		(x, y, n) = in_map_int()
		print(solve(x, y, n))
main()


import time
import math
from sys import stdin, stdout

def I():
	return int(stdin.readline())

def In():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def Si():
	return sorted(list(map(int, stdin.readline().split())))

def Si():
	return sorted(list(map(int, stdin.readline().split())), reverse=True)

def P(x):
	return stdout.write(str(x) + '\n')

def Pi(x, y):
	return stdout.write(str(x) + ' ' + str(y))

def solve():
	for i in range(I()):
		(x, y, n) = In()
		m = n // x * x
		z = x - y
		if m + y <= n:
			P(m + y)
		else:
			P(m - z)
solve()


import math
n = int(input())
while n:
	(x, y, k) = list(map(int, input().split()))
	ans = y
	ans = ans + x * math.floor((float(k) - float(y)) / float(x))
	if ans > k:
		ans -= x
	print(ans)
	n -= 1


t = int(input())
for _ in range(t):
	(x, y, n) = input().split()
	(x, y, n) = (int(x), int(y), int(n))
	i = int(n % x)
	k = n - i - (x - y)
	if i == y:
		print(n)
	elif n < x:
		print(y)
	elif i > y:
		print(n - (i - y))
	else:
		print(k)