Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define SC scanf
- #define PF printf
- #define ull unsigned long long
- #define ld long double
- #define D double
- #define F first
- #define S second
- #define pb push_back
- #define pf push_front
- #define MP make_pair
- #define sort_a(a) sort(a.begin(),a.end());
- #define sort_d(a) sort(a.rbegin(),a.rend());
- #define READ(f) freopen(f, "r", stdin)
- #define WRITE(f) freopen(f, "w", stdout)
- #define rev(s) reverse(s.begin(),s.end())
- #define it(it,mp) for(auto it=mp.begin() ; it!=mp.end() ; it++)
- #define IOS ios_base :: sync_with_stdio(false); cin.tie(NULL);
- const int N = 1e5 + 5;
- const int inf = 1e9 + 1;
- const double eps = 1e-15;
- const double EPS = 1e-9;
- const double PI = acos(-1.0);
- typedef long long int ll;
- typedef pair<int,int> PII;
- int main()
- {
- IOS
- // READ("test.txt");
- //WRITE("");
- ll t, n ;
- string s;
- cin >> t ;
- while(t--)
- {
- cin >> n>> s;
- bool flag = true;
- int cnt =0 ,pos =0 , pp = 0,ok=0;
- for(int i=0 ; i<n ; i++)
- {
- int tt = s[i]-'0';
- if(tt&1 ){
- cnt++;
- if(ok==0){
- pos = i,ok=1;
- }
- }
- if(cnt >1 && tt&1)pp = i ;
- }
- if(cnt<=1)
- {
- cout<<-1<<endl;
- }
- else
- {
- if(cnt&1)
- {
- for(int i=0 ; i<n ; i++)
- {
- if(i ==pp ){
- cout<<s[s.size()-1];
- }
- else if(i==n-1){
- cout<<s[pp];
- }
- else if(i!=pos)
- cout<<s[i];
- }
- cout<<endl;
- }
- else
- {
- // cout<<pos<<pp<<endl;
- for(int i=0 ; i<n ; i++)
- {
- if(i ==pp ){
- cout<<s[s.size()-1];
- }
- else if(i==n-1){
- cout<<s[pp];
- }
- else cout<<s[i];
- }
- cout<<endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement