We need to analyze the problem. We have infinite hotel rooms indexed by all integers Z. Initially each room k has a guest. After shuffling, each guest from room k moves to room k + a_{k mod n}. So the mapping f: Z -> Z is defined by f(k) = k + a_{k mod n}. We need to check whether f is a permutation of Z (bijection). That is, whether f is one-to-one and onto (since domain and codomain are both countable infinite, onto follows from one-to-one if we can argue it's a bijection on Z? Actually for infinite sets, a function can be one-to-one but not onto. For example, f(k) = 2k is injective but not surjective on Z. So we need both injectivity and surjectivity. But perhaps for this specific form, it's equivalent to checking that the mapping is a permutation: i.e., it is bijective if and only if the function is both injective and surjective. Since domain is Z, but we only have f defined on all integers. We need to determine if f is a bijection.
Alternatively, we might think about the condition that after moving, there is exactly one guest per room, i.e., the mapping is a permutation. So we need to check if f is a bijection.
Now we need to process up to 2e5 total n across test cases, each a_i can be large. Need an efficient check.
Let's denote n as the period of the pattern for the shift: a_i depends only on residue class modulo n. So f(k) = k + a_r where r = k mod n (with mod defined as 0 <= r < n). So the function is "affine" on each residue class modulo n: it's just a translation by a constant that depends on the residue.
We want to know if f: Z -> Z is bijective.
We can think of f as a map on Z. Consider breaking Z into residue classes mod n. For each residue r (0 <= r < n), the map on that class is: for any integer m, let k = m n + r, then f(k) = m n + r + a_r = n m + (r + a_r). So if we write f(k) in terms of quotient and remainder mod n: We can compute f(k) mod n: (r + a_r) mod n. And the quotient part: m + floor((r + a_r)/n) perhaps? Actually careful: k = nm + r, f(k) = nm + r + a_r. Write r + a_r = n * q_r + s_r, where s_r = (r + a_r) mod n (0 <= s_r < n) and q_r = floor division (could be negative if a_r negative? But using Euclidean division: r + a_r = n * q_r + s_r where 0 <= s_r < n, q_r is integer possibly negative). Then f(k) = nm + nq_r + s_r = n*(m+q_r) + s_r. So f maps the residue class r to residue class s_r = (r + a_r) mod n. And the quotient (the integer part) gets shifted by q_r (which depends only on r, not m). So on each residue class r, f acts as a translation on the "index" m by q_r, and changes the residue to s_r.
Thus we can view the mapping as follows: Represent each integer as a pair (m, r) with m ∈ Z, r ∈ [0, n-1], corresponding to integer x = n*m + r. Then f(m, r) = (m + q_r, s_r) where s_r = (r + a_r) mod n and q_r = floor((r + a_r)/n). (Note: Since we are using standard remainder with 0≤r<n, we need to define q_r = (r + a_r - s_r)/n, which is integer.)
Now, f is bijective if and only if the map from Z x [0,n-1] to Z x [0,n-1] given by (m, r) -> (m + q_r, s_r) is bijective.
This is reminiscent of an affine transformation on a lattice. The map can be seen as: (m, r) -> (m, r) * something? But note that the change in residue class depends only on r, not on m. So it's a kind of "skew" permutation on the finite set of residue classes combined with a shift on the integer coordinate.
We can analyze conditions for bijectivity.
First, observe that f is bijective if and only if the map on residues s: [0,n-1] -> [0,n-1] given by r -> s_r = (r + a_r) mod n is a permutation of the residues. Why? Let's think.
If s is not a permutation, then some residue class t has no preimage, i.e., for all r, s_r != t. Then consider any integer y with residue t. Is there any x such that f(x)=y? If s is not onto, then no x with appropriate residue can map to that residue class, but perhaps there could be x with other residues? Actually f(x) residue is s_{x mod n}. So if t is not in the image of s, then for any x, f(x) mod n != t. Hence f is not surjective (no integer maps to numbers with residue t). So s must be a permutation (bijection on the set of residues) for f to be surjective. Conversely, if s is a permutation, then every residue class is covered. However, we also need injectivity: if s is a permutation, but could there be collisions across different residues or same residue? Let's analyze injectivity: Suppose f(m1, r1) = f(m2, r2). That gives:
- s_{r1} = s_{r2} (so residues equal). Since s is a permutation, this implies r1 = r2 (since s is injective). So r1 = r2 = r.
- Then m1 + q_r = m2 + q_r => m1 = m2. So injectivity holds. Thus if s is a permutation, then f is injective (and surjective as argued? We argued surjectivity also requires s to be onto. So if s is a permutation (bijective), then surjectivity follows: For any target (M, t), since s is onto, there exists unique r such that s_r = t. Then we need m such that m + q_r = M, i.e., m = M - q_r, which is an integer. So preimage exists. So f is bijective exactly when s is a permutation.
Wait, careful: In surjectivity, we need for any integer y, find x such that f(x)=y. Represent y as (M, t). Choose r = s^{-1}(t). Then we need x = nm + r such that f(x) = n(m+q_r) + t = n*M + t. So we need m+q_r = M => m = M - q_r. Since m must be integer, that's fine (q_r is integer). So indeed any integer M works. So surjectivity holds provided s is bijective. So condition is: s_r = (r + a_r) mod n must be a permutation of [0, n-1].
But is there any subtlety? The definition of mod: remainder non-negative. Our derivation used the representation with 0 <= r < n. That's fine. And we used q_r = (r + a_r - s_r)/n. That's integer. So condition is necessary and sufficient? Let's test with examples.
Example 1: n=1, a=[14]. Then r=0, s_0 = (0+14) mod 1 = 0, so s is identity permutation (trivially). So condition says YES. Output YES. Good.
Example 2: n=2, a=[1, -1]. Compute:
r=0: s0 = (0+1) mod 2 = 1
r=1: s1 = (1 + (-1)) mod 2 = 0 mod2 =0. So s = [1,0] which is a permutation (swap). So condition says YES. Output YES. Good.
Example 3: n=4, a=[5,5,5,1]
r0: 0+5=5 mod4=1 -> s0=1
r1: 1+5=6 mod4=2 -> s1=2
r2: 2+5=7 mod4=3 -> s2=3
r3: 3+1=4 mod4=0 -> s3=0
Permutation (0->1,1->2,2->3,3->0). So YES. Output YES.
Example 4: n=3, a=[3,2,1]
r0: 0+3=3 mod3=0 -> s0=0
r1: 1+2=3 mod3=0 -> s1=0
r2: 2+1=3 mod3=0 -> s2=0
So s is not a permutation (all map to 0). So condition says NO. Output NO. Good.
Example 5: n=2, a=[0,1]
r0: 0+0=0 mod2=0 -> s0=0
r1: 1+1=2 mod2=0 -> s1=0
Not permutation, NO. Output NO.
Example 6: n=5, a=[-239, -2, -100, -3, -11]
Compute residues:
r0: 0 + (-239) = -239. Mod 5? remainder: We need -239 mod 5 = smallest nonnegative r such that -239 - r divisible by 5. Usually -239 = 5*(-48) + 1? Actually 5*(-48) = -240, remainder 1? Let's compute: -239 = 5 * (-48) + 1? Check: 5*(-48) = -240, so -239 - 1 = -240 divisible by 5, remainder 1 (since 0 <= 1 <5). So s0 = 1.
r1: 1 + (-2) = -1. -1 mod5 =? -1 = 5*(-1)+4? Actually 5*(-1) = -5, remainder 4? Need -1 - r divisible by 5. If r=4, -1-4=-5 divisible by5. So s1 = 4.
r2: 2 + (-100) = -98. -98 mod5? 5*(-20) = -100, remainder 2? -98 = 5*(-20) + 2? Actually -100 +2 = -98, so remainder 2? But we need remainder nonnegative: -98 - 2 = -100 divisible by5, so s2=2.
r3: 3 + (-3) = 0, mod5 = 0 -> s3=0.
r4: 4 + (-11) = -7. -7 mod5? -7 = 5*(-2) + 3? Because 5*(-2)=-10, remainder 3? Actually -7 -3 = -10 divisible by5, so s4=3.
So s = [1,4,2,0,3]. That's a permutation (0->1,1->4,2->2,3->0,4->3) which indeed covers all 0-4. So condition says YES. Output YES. Good.
So condition seems to match all examples.
Thus the problem reduces to: Given array a of length n, compute s_i = (i + a_i) mod n (with the given mod definition: remainder in [0, n-1]). Check whether the set of s_i is exactly all residues from 0 to n-1 exactly once (i.e., it is a permutation). That's it.
But wait, we must be careful: In our derivation we assumed that the map (m,r) -> (m+q_r, s_r) is bijective if s is permutation. However, is there any additional requirement that q_r must be integers? They are integers by definition. And as we argued, for surjectivity we need to solve m = M - q_r; m can be any integer, so no restriction. So condition is exactly that s is a permutation.
But let's double-check with potential edge cases: Could it be that despite s being a permutation, f fails to be one-to-one due to some wrap-around effect because we are using modulo? Our analysis using the (m,r) representation is rigorous: each integer has unique representation as (m, r) with m in Z, r in [0,n-1]. The mapping is (m,r) -> (m + q_r, s_r). If s is a permutation, then the map is invertible: Inverse: given (M, t), find r = s^{-1}(t), then m = M - q_r. So indeed it's bijective. So condition is both necessary and sufficient.
But is there any hidden nuance about the definition of mod? They define r = k mod n as smallest non-negative integer such that k - r is divisible by n. That's the usual Euclidean remainder. For negative numbers, we use that definition. In our derivation we used r = k mod n as the remainder, which we used as the residue class index. That's correct because we defined k = n*m + r with 0 <= r < n. So that matches the problem. And we computed s_r = (r + a_r) mod n, which uses the same mod operation. So fine.
Thus solution: For each test case, read n and array a[0..n-1]. Compute b[i] = ((i + a[i]) % n + n) % n? Since a[i] can be negative, we need to compute modulo properly. In C++ the % operator gives remainder with sign of dividend, which for negative numbers yields negative remainder. So we need to adjust to get 0..n-1. Standard: ((i + a[i]) % n + n) % n. But careful: i + a[i] might be large, but we can compute modulo with long long. Summation fits within 64-bit? i up to 2e5, a_i up to 1e9, so sum fits in ~1e9, but could be near -1e9? Actually a_i as low as -1e9, i up to 2e5, so i + a_i could be as low as -1e9+something, absolute value ~1e9, so 64-bit safe. But total sum across test cases fine.
Alternative: Use ( ( (i + a[i]) % n ) + n ) % n to get non-negative remainder. But ensure we use modulo on possibly negative numbers, so adjust.
Then check if all b[i] are distinct and cover 0..n-1. Equivalent to checking that b is a permutation of 0..n-1. Since n up to 2e5, we can use boolean array visited of size n per test case, but sum of n is 2e5, so O(n) per test case is fine. Or we can sort b and check.
We'll need to reinitialize the visited array for each test case efficiently. Since total n <= 2e5, we can use a global array of length 2e5+5, and use a timestamp technique, or we can allocate fresh vector for each test case. That's okay within constraints (2e5 bool vector per test, total memory sum ~2e5). But if we allocate a new vector of size n for each test case, total allocated memory across tests could be sum of n, which is okay. However, creating many vectors might have overhead, but t up to 1e4, but sum n is limited; many tests could have small n, e.g., n=1 each, 1e4 tests each with vector of size 1 is fine. So we can simply use a vector visited(n,0) or a vector; but careful: resetting a global array of max n size for each test using a loop might be O(n) per test anyway, but total O(total n) if we only loop over n entries for each test? Actually if we have global visited array of length N_MAX = 200000, and we use a version ID, that is efficient. But simple vector per test is also fine because sum of n <= 2e5, so total memory allocation and initialization over all tests will be O(total n). Actually if we create a vector of size n for each test and fill with false, that's O(n) per test, total O(total n) = 2e5. So it's fine. However, note that for each test, we allocate a new vector of size n, initialize to zero. Sum of sizes = total n, so total initialization work = 2e5, which is fine. But if we allocate a vector and then use assignment or constructor with count, that's O(n). So overall O(total n). So we can do that.
But careful: t up to 1e4, so if we allocate many small vectors, overhead may be noticeable but within limits (C++ can handle). Alternatively, we can use a map or set to check uniqueness. But O(n log n) per test would also be okay (total 2e5 log(2e5) is fine). However simpler: compute b, sort, then check if b[i] == i (after sorting) and all distinct? Since sorting would be O(n log n) total sum of n log n across tests, where sum n=2e5, but each test's n could be up to 2e5, sorting that is fine. But using visited array O(n) is even simpler. I'll use visited array.
But note: The visited array should check for duplicates. If any b[i] is outside [0, n-1]? By modulo it's always within range. So we just need to see if we get exactly each number once. Use a frequency array of size n. For each b[i], increment count. If any count !=1 at the end, output NO. But careful: Could some b[i] be > n-1? No, modulo ensures 0..n-1.
Thus algorithm:
For each test case:
- read n
- read array a
- create vector cnt(n,0)
- for i in 0..n-1:
val = ((i + a[i]) % n + n) % n // ensure positive
cnt[val]++
- if every cnt[j] == 1, print YES else NO.
Complexities: O(n) per test, total O(2e5).
Now let's double-check if there is any edge case that breaks this condition despite s being permutation? The derivation seems solid. But wait, we must ensure that the mapping defined by f(k) = k + a_{k mod n} is indeed a function from Z to Z. It is. And we argued bijection iff s permutation. Let's double-check with a more tricky scenario: Suppose n=3, a = [1, 1, 1]. Then s: r0: (0+1)%3=1; r1: (1+1)%3=2; r2: (2+1)%3=0. So permutation, so should be YES. Let's test manually:
k=0 -> to 1
k=1 -> to 2
k=2 -> to 3
k=3 -> 3 mod 3=0, a0=1 -> 3+1=4
k=4 -> mod1? 4 mod3=1, a1=1 -> 4+1=5
k=5 -> mod2, a2=1 ->6
So mapping: 0->1,1->2,2->3,3->4,4->5,5->6,... Looks like shift by 1? Actually it's not constant shift because guests with same residue shift by same amount. For r=0, always shift by 1. For r=1, shift by 1. For r=2, shift by 1. So overall f(k)=k+1 for all k? Let's check: For any k, k mod3 = r, a_r=1, so f(k)=k+1. Yes indeed. So it's just a translation by 1, which is bijective. Good.
Another test: n=2, a=[0,2]. s0:0 mod2=0; s1: (1+2)=3 mod2=1. Permutation? Yes, 0->0,1->1. So condition says YES. Let's see mapping: r=0: shift by 0; r=1: shift by 2. So k even -> stays; k odd -> +2. So map: 0->0,1->3,2->2,3->5,4->4,5->7,... Is this bijective? Let's test small numbers: Values hit: 0 (from 0), 1? Is any x maps to 1? Need x + a_{x mod 2} =1. If x even: x+0=1 => x=1, but 1 is odd, contradiction. If x odd: x+2=1 => x=-1, which is odd. So -1 maps to 1? Check: -1 mod2? -1 mod2 is 1 (since -1 = 2*(-1) + 1), a1=2 => -1+2=1. So yes. So mapping covers all integers. Also injective? If f(x)=f(y), consider residues. Since s is permutation, r must be same, then x=y. So yes, bijective. So condition holds.
What about n=2, a=[0, -2]. s0:0; s1:(1-2)=-1 mod2? -1 mod2 = 1? Because -1 = 2*(-1)+1. So s1=1. So permutation: 0->0,1->1. So condition says YES. Check mapping: even -> stays; odd -> -2. So mapping: 1->-1, 3->1, 5->3, ... seems bijective.
What about a case where q_r are not all zero, but s permutation still ensures bijection. Example: n=3, a = [4, -2, -2]. Compute: r0:0+4=4 mod3=1, s0=1, q0=(4)/3 floor? Actually (0+4)=4 => 4 = 31+1 => q0=1. r1:1-2=-1 mod3=2? Because -1 mod3 = 2 (since -1 = 3(-1)+2). So s1=2, q1 = floor division: ( -1 - 2)/3? That's messy; easier: r+a = -1, s=2 => q = (-1-2)/3 = -3/3 = -1. So q1=-1. r2:2-2=0 mod3=0, s2=0, q2=0. So s permutation (0->1,1->2,2->0). Condition says YES. Let's test injectivity manually: If two different k map to same, they must have same residue? Possibly okay. But let's test a few values: k=0 (r0) -> f=0+4=4; k=1 (r1) -> 1-2=-1; k=2 -> 2-2=0; k=3 -> mod0 -> 3+4=7; k=4 -> mod1 ->4-2=2; k=5 -> mod2 ->5-2=3; k=6 -> mod0 ->6+4=10; k=7 -> mod1 ->7-2=5; k=8 -> mod2 ->8-2=6; etc. So mapping sequence from 0: 4, -1,0,7,2,3,10,5,6,... Looks like it might be bijection. Let's check if any collisions: For example, does any other map to 4? Solve x + a_{x mod3}=4. For x mod3=0: x+4=4 => x=0. Mod1: x-2=4 => x=6, but 6 mod3=0 not 1. Mod2: x-2=4 => x=6, mod2=0? Actually 6 mod3=0, not 2. So only 0. Good.
Thus condition seems correct.
Now need to confirm there is no hidden issue about "room number could be any integer, including negative". Our mapping covers all integers. In surjectivity, we found for any target integer y, we can find x = something. That works regardless of sign. So fine.
Thus solution is straightforward.
But wait: Could there be a case where s is a permutation but f is not injective because of the quotient adjustment q_r? In our argument, if s is injective, then residues must match. But could two different r produce same s even if s is permutation? No, permutation means it is injective, so distinct r map to distinct s. So that's fine.
Thus answer is simply check if the set { (i + a_i) mod n } equals {0,1,...,n-1}.
Implementation details: compute (i + a_i) % n. In languages where % may give negative, adjust.
Alternatively, we can compute ((i + a[i]) % n + n) % n. But careful: (i + a[i]) % n in C++ for negative numbers yields negative remainder (or zero). For example, -5 % 3 = -2 (in C++98/11? Actually C++11 standardized modulo to follow truncation toward zero, so -5/3 = -1 (trunc toward zero) and remainder -5 - (-1)*3 = -2. So indeed remainder is -2. So we need to add n and then % n again. So: val = ((i + a[i]) % n + n) % n. But that double modulo might be unnecessary if we compute ((i + a[i]) % n + n) % n, which works even if the first remainder is negative. However, if the sum is large positive, the first % n yields 0..n-1, adding n gives n..2n-1, and % n again yields same as original. So it's safe.
But note that (i + a[i]) could be as large as ~ 1e9 + 2e5, which is fine for 32-bit signed? 1e9+2e5 = 1,000,200,000, which fits in signed 32-bit? Actually max 32-bit signed is 2,147,483,647, so okay. But sum could also be as low as -1e9, which is fine. So using 64-bit is safe but 32-bit also works. But be careful: If we do (i + a[i]) % n, if i + a[i] is negative, the result is negative. Adding n may not bring it into [0, n-1] if the negative remainder is less than -n? Actually if we compute x = (i + a[i]) % n, x will be in the range (-n+1) to (n-1) because the remainder magnitude is less than |n|. Actually C++ standard: For a/b truncates toward zero, remainder has sign of dividend, and |remainder| < |divisor|. So for divisor n>0, remainder is in (-n, n). More precisely, if x negative, remainder r satisfies -n < r <= 0. Actually e.g., -1 % 3 = -1 (since -1/3 truncates to 0, remainder -1). That is within -3 < r <= 0. So r is in range (-n, 0]. So adding n yields in (0, n], but if r=0, adding n gives n, then % n gives 0. If r=-1, adding n gives n-1, % n = n-1. So ((x % n) + n) % n works.
But simpler: use ((i + a[i]) % n + n) % n. Or we can use Python where % always returns non-negative. But we're doing C++.
We need to handle multiple test cases. Input constraints: sum n ≤ 2e5, so we can allocate array of that size each test or reuse.
I'll implement in C++:
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector cnt(n, 0);
for (int i = 0; i < n; i++) {
long long sum = i + a[i]; // use long long to avoid overflow? Actually int should be fine, but safe
int val = ((sum % n) + n) % n;
cnt[val]++;
}
bool ok = true;
for (int i = 0; i < n; i++) {
if (cnt[i] != 1) {
ok = false;
break;
}
}
cout << (ok ? "YES" : "NO") << "\n";
}
return 0;
}
But careful: i + a[i] could be as high as 2e5 + 1e9 = 1,000,200,000 which fits in 32-bit signed (max 2,147,483,647). So using int is safe but the modulo operation might overflow? Actually i + a[i] computed as int is okay. However, if a[i] is -1e9 and i=2e5, sum = -999800000, that's also within range. So int works. But I'll use long long for safety.
Now, we must consider one more nuance: In our derivation we assumed that the mapping f is from Z to Z given by f(k) = k + a_{k mod n}. But there is a subtlety: The modulo operation used in the problem for defining r = k mod n is the smallest non-negative integer such that k - r is divisible by n. So indeed r ∈ [0, n-1] uniquely. So our decomposition is correct.
Thus the solution is correct.
But wait, the problem statement says: "Then the shuffling works as follows. There is an array of n integers a_0,a_1,…,a_{n-1}. Then for each integer k, the guest in room k is moved to room number k+a_{kmod n}." So the index used in a is k mod n, as we used. Good.
Thus answer is indeed YES if and only if the set of (i + a_i) mod n is a permutation.
Now let's confirm the condition more thoroughly via group theory perspective: Consider the function f(k) = k + a_{k mod n}. Write k = nq + r. Then f(k) = nq + r + a_r = nq + (r + a_r). Let s = (r + a_r) mod n and t = floor((r + a_r)/n) (maybe negative). Then f(k) = n(q + t) + s. So the mapping on the quotient is q -> q + t, which is a shift, and the mapping on residues r -> s. If s is a permutation, then the whole map is a bijection because we can invert by subtracting t for the appropriate residue. So condition is necessary and sufficient.
Edge Cases: n=1, always a_0: s_0 = (0 + a_0) mod 1 = 0 always. So condition always true. So for n=1, always YES. Check: f(k) = k + a_0, which is a translation, bijective. So YES. Good.
Now we can produce final solution.
But wait, there might be a nuance regarding the modulo operation for negative a_i: Our computation of s uses mod n as defined, which yields a value between 0 and n-1. For the condition to be necessary, we argued that if s is not onto then f is not surjective. That is correct because if some residue t is missing, then there is no k such that f(k) ≡ t (mod n). But is it possible that f(k) could produce that residue via the quotient? No, because f(k) mod n = s_{k mod n} by definition: (k + a_{k mod n}) mod n = ( (k mod n) + a_{k mod n} ) mod n = (r + a_r) mod n = s_r. So f(k) mod n is always in the set {s_0,...,s_{n-1}}. So if that set is not all residues, f is not onto mod n, hence not onto overall. So necessary.
Now, is it possible that s is a permutation but f is not injective? Suppose s is injective, then if f(x)=f(y), we have s_{x mod n} = s_{y mod n} => x mod n = y mod n = r. Then f(x) = nq_x + r + a_r; f(y) = nq_y + r + a_r. Equality gives nq_x = nq_y => q_x = q_y => x=y. So injective. So condition sufficient.
Thus problem solved.
Now, consider potential overflow in modulo calculation: As we did, use long long.
Now, but there is a nuance: In computing (i + a_i) % n, we must be careful that (i + a_i) could be very large beyond 64-bit? Max magnitude: i up to 2e5, a_i up to 1e9, so sum magnitude up to ~1e9+2e5, which is ~1e9, fits in 32-bit. However, if there is a test case with n up to 2e5 but a_i up to 1e9, the sum fits in 32-bit signed (max 2,147,483,647) but 1e9+2e5 = 1,000,200,000, safe. However, if a_i is 1e9 and i is 2e5, sum=1,000,200,000 < 2.147e9, so safe. If a_i = -1e9, sum negative with magnitude ~1e9, safe. So int works. But to be safe, use long long.
Now, we can further simplify: Because s_i = (i + a_i) mod n, we can compute ( (i + a[i]) % n + n ) % n. But note: In C++ for positive numbers, % n yields in [0, n-1]. For negative, yields negative. So fine.
Now test on the given examples.
Implementation done.
But I want to double-check the fifth test: n=2, a=[0,1] we computed s0=0, s1=0 -> not perm -> NO. That matches.
Now we need to output YES/NO.
Thus final solution is trivial.
But wait, the problem might be trick: maybe condition is that the mapping is a permutation of Z if and only if the sum of a_i is something? But examples show not.
Alternatively, one might think about the function being bijective if and only if the set of differences etc. But no.
Thus answer is simple.
Now, however, consider the possibility that the mapping is not well-defined due to overflow? No.
Now, verify with more random cases. Let's test n=3, a=[-1, -1, -1]. s0: -1 mod3 = 2; s1: 0 mod3? 1-1=0 mod3=0; s2: 1 mod3? 2-1=1 mod3=1. So s = [2,0,1] permutation -> YES. f(k)=k-1 for all k? Check: r=0: 0-1=-1; but -1 mod3? -1 mod3 is 2, not 0, but a0=-1? Actually f(k)=k + a_{k mod n}. For any k, a_{k mod n} = -1. So f(k)=k-1, which is shift by -1, bijective. So YES.
Now n=4, a=[0,0,0,0]. s=[0,1,2,3] -> identity permutation -> YES. f(k)=k, identity, bijective.
Now n=4, a=[1,2,3,0]. s0:1; s1:3; s2:5 mod4=1? Wait 2+2=4? Let's compute: r0:0+1=1 mod4=1; r1:1+2=3 mod4=3; r2:2+3=5 mod4=1; r3:3+0=3 mod4=3. So s = [1,3,1,3], not perm -> NO. Indeed likely not bijective.
So condition works.
Thus solution is as described.
Now complexity: O(total n). So acceptable.
Now final answer: For each test case, compute residues, check if they form permutation.
Implementation details: Use vector cnt(n,0) and then check.
But we can also use bitset or set but O(n) with array is simplest.
Be careful about indexing: i from 0 to n-1 inclusive.
Now, I'll produce the final answer.
But I'll also think about possible pitfalls: Could there be any scenario where the mapping is not a bijection despite s being a permutation, due to the fact that we used the Euclidean remainder for the shift? Actually the mapping is defined using the same mod as we used for a indexing. So it's consistent.
What about if a_i are huge, e.g., a_i = 10^9? Then s_i = (i + a_i) mod n. That is fine.
What about if n is large and we allocate cnt of size n each test? That's fine.
Thus final code.
One more nuance: The problem statement says "There is exactly one guest in every room." And "determine if there is still exactly one guest assigned to each room." So we need to check if after moving, each room has exactly one guest. That is exactly bijection.
Now, verify the solution with some more tricky test: n=2, a=[1, -1] we already did.
Now check n=2, a=[-1, 1]: s0: -1 mod2=1; s1: 2 mod2=0 => perm, YES. That mapping: even -> -1 shift; odd -> +1 shift. Might be bijective.
Now test n=3, a=[2, -4, 2]. Compute s0: 2 mod3=2; s1: -3 mod3=0? 1-4=-3 mod3=0; s2: 4 mod3=1. Permutation [2,0,1] -> YES. f: residues: r0 -> +2; r1-> -4; r2-> +2. Check injectivity: suppose f(x)=f(y). Need to verify no collisions. Because s perm, residues same -> r same. Then equation gives x=y. So okay.
Now we are convinced.
Thus answer: For each test case compute b[i] = (i + a[i] mod n + n) mod n, then check if all numbers 0..n-1 appear exactly once.
Implementation:
Pseudo:
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector a(n);
for(int i=0;i<n;i++) cin>>a[i];
vector cnt(n,0);
bool ok=true;
for(int i=0;i<n;i++){
ll val = (i + a[i]) % n;
if(val < 0) val += n;
cnt[val]++;
if(cnt[val] > 1) ok=false; // early break may skip some increments but we can just break and then still need to consume input? Actually we still need to read all a_i? Already read a_i before loop. Wait, we are iterating over already read a. So we can break early without reading further? But we already read a. So we can break early if we find duplicate? But we still need to output after processing loop. It's okay to break early but we still need to finish the loop? Actually if we break early we can skip setting other cnt entries, but we only need to know if any duplicate or missing. So we could break when duplicate found, but we need to ensure we don't access out of bounds if we break before finishing. But we have already read all a. So we can simply set a flag and break. However, we also need to ensure that if duplicate found early, we still consider that the answer is NO; but we might later have a duplicate that we didn't catch? No, if we found a duplicate, answer is NO; we can break out. But we also need to ensure we don't have any missing numbers? Actually if duplicates exist, it's automatically not a permutation (since sum of counts would be n but duplicates mean some numbers missing). So we can early exit when any count becomes 2. That's fine. However, if we break early, we don't finish reading the a array? But we have already read all a. So no issue. But careful: In our code we are reading a in a separate loop. So the loop for computing val is after reading all a. So we can break early. That's fine.
But to be safe, we can just compute all and then check counts.
I'll compute all then check.
Potential overflow in modulo: Use ( (i + a[i]) % n + n) % n.
But if (i + a[i]) is negative large, and we do % n, it's negative. Adding n once may still be negative? Actually if remainder is negative, say -5 and n=3, -5%3? Let's compute: -5/3 truncates to -1, remainder -5 - (-1)*3 = -5+3=-2. So remainder is -2. Then adding 3 gives 1, positive. So one addition of n is sufficient because remainder is in (-n, 0]. Actually remainder r satisfies -n < r <= 0. So adding n yields (0, n]. If r=0, +n = n, then % n gives 0. If r negative, -n < r < 0, so adding n yields 0 < r+n < n, which is already in (0, n-1). So ( (i+a[i]) % n + n ) % n is correct but the second % n is only needed to convert n to 0 when remainder was exactly 0? Actually if remainder was 0, then (0 + n) % n = 0. So it's fine. But we could also do: val = ((i + a[i]) % n + n) % n. That's fine. Or we could do: val = ((i + a[i]) % n + n) % n; But we could also compute: val = (i + a[i]) % n; if(val < 0) val += n; That's simpler.
So code:
long long sum = i + a[i];
int val = sum % n;
if(val < 0) val += n;
cnt[val]++;
Yes.
Now, what if n=0? But n>=1.
Now, let's consider if there is any scenario where s is a permutation but mapping not onto because of the q_r causing the "m" values to go out of range? But m is integer, no restrictions. So it's fine.
Now, final step: Output "YES" or "NO".
Thus problem solved.
But wait: In the problem statement, they say "There is an array of n integers a_0,...,a_{n-1}. Then for each integer k, the guest in room k is moved to room number k+a_{kmod n}." So the array indices correspond to the remainder. In our analysis we used i from 0 to n-1. That's correct.
Now, perhaps there is a subtlety: The definition of mod for negative k: "kmod n denote the remainder when k is divided by n. More formally, r=kmod n is the smallest non-negative integer such that k-r is divisible by n." That is exactly what we used.
Thus our solution is correct.
Now I'll produce final answer.
But we should also consider if there is any trick regarding the infinite nature: The mapping may be bijective even if s is not a permutation? Possibly if the mapping is not surjective but still each room has exactly one guest? Actually if it's not surjective, some rooms become empty, which violates "exactly one guest assigned to each room". So we need surjectivity. So condition is necessary.
Now, I want to prove the sufficiency more formally: Suppose s is a permutation. Then define for each integer y, let r = s^{-1}(y mod n) and m = floor(y/n) - q_r. Then x = n*m + r yields f(x) = y. This is valid because m integer. So surjective. And injective as argued. So indeed.
Thus final answer.
Now I'll think about possible alternative interpretations: Could the array a be used cyclically? For example, k mod n is computed, then a_{k mod n} is used. That's what we did.
Now edge case: n=0 is not allowed.
Now complexity: O(total n). Memory: O(max n) per test but sum small.
Now, the problem is from Codeforces likely (maybe round #...). I've seen similar problem: "Hilbert's Hotel" indeed a known problem. The solution is exactly checking if the set of (i + a_i) mod n is a permutation.
Thus finalize.
But before final answer, let's see if there is any pitfall with integer overflow when using int for cnt indices? No.
Now, we can also use set to check uniqueness, but array is fine.
Now I'll produce final solution.
But we should be careful about reading large input: use fast I/O.
Now, let's include explanation in final response.
Now, the response should contain the solution approach and final code.
Now produce final.
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
vector<int> cnt(n, 0);
for (int i = 0; i < n; ++i) {
// compute (i + a[i]) mod n in the mathematical sense (0 .. n-1)
ll sum = i + a[i];
int r = sum % n;
if (r < 0) r += n;
cnt[r]++;
}
bool ok = true;
for (int i = 0; i < n; ++i) {
if (cnt[i] != 1) {
ok = false;
break;
}
}
cout << (ok ? "YES" : "NO") << "\n";
}
return 0;
}