# A. Digit Game SOLUTION CODEFORCES

Page Contents

## Digit Game SOLUTION CODEFORCES

Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play tt matches of a digit game…

In each of tt matches of the digit game, a positive integer is generated. It consists of nn digits. The digits of this integer are numerated from 11 to nn from the highest-order digit to the lowest-order digit. After this integer is announced, the match starts.

Agents play in turns. Raze starts. In one turn an agent can choose any unmarked digit and mark it. Raze can choose digits on odd positions, but can not choose digits on even positions. Breach can choose digits on even positions, but can not choose digits on odd positions. The match ends, when there is only one unmarked digit left. If the single last digit is odd, then Raze wins, else Breach wins.

It can be proved, that before the end of the match (for every initial integer with nn digits) each agent has an ability to make a turn, i.e. there is at least one unmarked digit, that stands on a position of required parity.

For each of tt matches find out, which agent wins, if both of them want to win and play optimally.Input

First line of input contains an integer tt (1≤t≤100)(1≤t≤100)  — the number of matches.

The first line of each match description contains an integer nn (1≤n≤103)(1≤n≤103)  — the number of digits of the generated number.

The second line of each match description contains an nn-digit positive integer without leading zeros.Output

For each match print 11, if Raze wins, and 22, if Breach wins.

Example

input

```4
1
2
1
3
3
102
4
2069
```

output

```2
1
1
2
```

Note

In the first match no one can make a turn, the only digit left is 22, it’s even, so Breach wins.

In the second match the only digit left is 33, it’s odd, so Raze wins.

In the third match Raze can mark the last digit, after that Breach can only mark 00. 11 will be the last digit left, it’s odd, so Raze wins.

In the fourth match no matter how Raze plays, Breach can mark 99, and in the end there will be digit 00. It’s even, so Breach wins.

### Solution:

Program C++:

``````#include<bits/stdc++.h>
using namespace std;
int T,n,a;
signed main()
{
cin>>T;
while (T--)
{
memset(a,0,sizeof a);
string str;
cin>>n>>str;
for (int i=0;i<n;i++) a[(i+1)%2][int(str[i]-'0')%2]++;
if (n%2==1) if (a) puts("1");else puts("2");
if (n%2==0) if (a) puts("2");else puts("1");
}
return 0;
} ``````

Program Java:

``````
import java.util.*;
import java.io.*;

public class Digit_Game {

static int mod = (int) (1e9 + 7);
public static void main(String[] args) throws java.lang.Exception {
while(t-->0) {
int c1=0,c2=0;
for (int i = 0; i < n; i++) {
if(((i+1)&1)==0 && (s.charAt(i)&1)==0) ++c2;
if(((i+1)&1)==1 && (s.charAt(i)&1)==1) ++c1;
}
if((n&1)==1) {
System.out.println(c1!=0? 1 : 2);
}else {
System.out.println(c2!=0? 2 : 1);
}
}
}
}``````

Program Python:

``````for i in range(int(input())):
aa=int(input())
a=input()
for i in range(1-(aa%2),aa,2):
b=1+(aa%2)
if int(a[i])%2==aa%2:
b+=1
break
print(2 if b==2 else 1)``````