A. Even But Not Even

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Let's define a number ebne (even but not even) if and only if its sum of digits is divisible by 22 but the number itself is not divisible by 22. For example, 1313, 12271227, 185217185217 are ebne numbers, while 1212, 22, 177013177013, 265918265918 are not. If you're still unsure what ebne numbers are, you can look at the sample notes for more clarification.

You are given a non-negative integer ss, consisting of nn digits. You can delete some digits (they are not necessary consecutive/successive) to make the given number ebne. You cannot change the order of the digits, that is, after deleting the digits the remaining digits collapse. The resulting number shouldn't contain leading zeros. You can delete any number of digits between 00 (do not delete any digits at all) and n−1n−1.

For example, if you are given s=s=222373204424185217171912 then one of possible ways to make it ebne is: 222373204424185217171912 →→ 2237344218521717191. The sum of digits of 2237344218521717191 is equal to 7070 and is divisible by 22, but number itself is not divisible by 22: it means that the resulting number is ebne.

Find any resulting number that is ebne. If it's impossible to create an ebne number from the given number report about it.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001≤t≤1000)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤30001≤n≤3000)  — the number of digits in the original number.

The second line of each test case contains a non-negative integer number ss, consisting of nn digits.

It is guaranteed that ss does not contain leading zeros and the sum of nn over all test cases does not exceed 30003000.

Output

For each test case given in the input print the answer in the following format:

  • If it is impossible to create an ebne number, print "-1" (without quotes);
  • Otherwise, print the resulting number after deleting some, possibly zero, but not all digits. This number should be ebne. If there are multiple answers, you can print any of them. Note that answers with leading zeros or empty strings are not accepted. It's not necessary to minimize or maximize the number of deleted digits.

Example

input

Copy

4
4
1227
1
0
6
177013
24
222373204424185217171912

output

Copy

1227
-1
17703
2237344218521717191

Note

In the first test case of the example, 12271227 is already an ebne number (as 1+2+2+7=121+2+2+7=12, 1212 is divisible by 22, while in the same time, 12271227 is not divisible by 22) so we don't need to delete any digits. Answers such as 127127 and 1717 will also be accepted.

In the second test case of the example, it is clearly impossible to create an ebne number from the given number.

In the third test case of the example, there are many ebne numbers we can obtain by deleting, for example, 11 digit such as 1770317703, 7701377013 or 1701317013. Answers such as 17011701 or 770770 will not be accepted as they are not ebne numbers. Answer 013013 will not be accepted as it contains leading zeroes.

Explanation:

  • 1+7+7+0+3=181+7+7+0+3=18. As 1818 is divisible by 22 while 1770317703 is not divisible by 22, we can see that 1770317703 is an ebne number. Same with 7701377013 and 1701317013;
  • 1+7+0+1=91+7+0+1=9. Because 99 is not divisible by 22, 17011701 is not an ebne number;
  • 7+7+0=147+7+0=14. This time, 1414 is divisible by 22 but 770770 is also divisible by 22, therefore, 770770 is not an ebne number.

In the last test case of the example, one of many other possible answers is given. Another possible answer is: 222373204424185217171912 →→ 22237320442418521717191 (delete the last digit).

解题说明:题意是给定的数字变成一个奇数,但是各个位数之和为偶数。做法是直接截取一个奇数。
从最后往前删,直到是奇数为止,再判断位数之和,是奇数的话删除一个奇数,偶数的话就直接输出。



#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

typedef long long ll;
char s[3010];
int main()
{
	int t;
	scanf("%d", &t);
	while (t--) 
	{
		int n;
		scanf("%d%s", &n, s + 1);
		int a = -1, b = -1;
		for (int i = 1; i <= n; i++)
		{
			if ((s[i] - '0') & 1)
			{
				if (a == -1)
				{
					a = i;
				}
				else
				{
					b = i;
					break;
				}
			}
		}
		if (a != -1 && b != -1)
		{
			for (int i = a; i <= b; i++)
			{
				printf("%c", s[i]);
			}
			printf("\n");
		}
		else
		{
			printf("-1\n");
		}
	}
	return 0;
}
发布了1769 篇原创文章 · 获赞 388 · 访问量 279万+

猜你喜欢

转载自blog.csdn.net/jj12345jj198999/article/details/104587859