using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp80
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] divisors = new int[100001];
            int ones = 0;
            if (n == 1)
            {
                Console.WriteLine(1);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (a[i]==1)
                    {
                        ones++;
                    }
                    if (a[i] % 2 == 0)
                    {
                        divisors[2]++;
                    }
                    else
                    {

                        for (int j = 1; j <= Math.Sqrt(a[i]); j++)
                        {
                            if (a[i] % j == 0)
                            {
                                divisors[j]++;
                                if (a[i]/j!=j)
                                {
                                    divisors[a[i] / j]++;
                                }
                            }
                        }
                    }
                }
                int max = 0;
                for (int i = 2; i < 100001; i++)
                {
                    if (divisors[i]>max)
                    {
                        max = divisors[i];
                    }
                }
                Console.WriteLine(max>ones?max:ones);
            }

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp80
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] divisors = new int[100001];
            if (n == 1)
            {
                Console.WriteLine(1);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (a[i] % 2 == 0)
                    {
                        divisors[2]++;
                    }
                    else
                    {
                        for (int j = 3; j <= Math.Sqrt(a[i]); j++)
                        {
                            if (a[i] % j == 0)
                            {
                                divisors[j]++;

                            }
                        }
                    }
                }
                Console.WriteLine(divisors.Max());
            }

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp80
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] divisors = new int[100001];
            if (n == 1)
            {
                Console.WriteLine(1);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (a[i] % 2 == 0)
                    {
                        divisors[2]++;
                    }
                    else
                    {
                        for (int j = 1; j <= Math.Sqrt(a[i]); j++)
                        {
                            if (a[i] % j == 0)
                            {
                                divisors[j]++;

                            }
                        }
                    }
                }
                Console.WriteLine(divisors.Max());
            }

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp80
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] divisors = new int[100001];
            if (n == 1)
            {
                Console.WriteLine(1);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (a[i] % 2 == 0)
                    {
                        divisors[2]++;
                    }
                    else
                    {
                        if (a[i]==3)
                        {
                            divisors[3]++;

                        }
                        for (int j = 3; j <= Math.Sqrt(a[i]); j++)
                        {
                            if (a[i] % j == 0)
                            {
                                divisors[j]++;
                                if (a[i]/j!=j)
                                {
                                    divisors[a[i] / j]++;
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(divisors.Max());
            }

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp80
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] divisors = new int[100001];
            if (n == 1)
            {
                Console.WriteLine(1);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (a[i] % 2 == 0)
                    {
                        divisors[2]++;
                    }
                    else
                    {

                        for (int j = 1; j <= Math.Sqrt(a[i]); j++)
                        {
                            if (a[i] % j == 0)
                            {
                                divisors[j]++;
                                if (a[i]/j!=j)
                                {
                                    divisors[a[i] / j]++;
                                }
                            }
                        }
                    }
                }
                int max = 0;
                for (int i = 2; i < 100001; i++)
                {
                    if (divisors[i]>max)
                    {
                        max = divisors[i];
                    }
                }
                Console.WriteLine(max);
            }

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp80
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] divisors = new int[100001];
            if (n == 1)
            {
                Console.WriteLine(1);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (a[i] % 2 == 0)
                    {
                        divisors[2]++;
                    }
                    else
                    {
                        for (int j = 1; j <= Math.Sqrt(a[i]); j++)
                        {
                            if (a[i] % j == 0)
                            {
                                divisors[j]++;

                            }
                        }
                    }
                }
            }
            Console.WriteLine(divisors.Max());
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] power = new int[a.Length];
            int max = 0;
            for(int i=0;i<n;i++)
            {
                power[i] = Convert.ToInt32(a[i]);
                if (max < power[i])
                    max = power[i];
            }
            int sqrt = Convert.ToInt32(Math.Sqrt(max));
            int max1 = 1;
            int qanak=0;
            for(int i=2;i<=sqrt;i++)
            {
                for(int j=0;j<n;j++)
                {
                    if (power[j] % i == 0)
                        qanak++;
                }
                if (max1 < qanak)
                    max1 = qanak;
                qanak = 0;
            }
            for (int j = 0; j < n; j++)
            {
                if (power[j] == max)
                    qanak++;
            }
            if (max1 < qanak)
                Console.WriteLine(qanak);
            else
                Console.WriteLine(max1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] power = new int[a.Length];
            int max = 0;
            for(int i=0;i<n;i++)
            {
                power[i] = Convert.ToInt32(a[i]);
                if (max < power[i])
                    max = power[i];
            }
            int max1 = 1;
            int qanak=0;
            for(int i=2;i<=max;i++)
            {
                for(int j=0;j<n;j++)
                {
                    if (power[j] % i == 0)
                        qanak++;
                }
                if (max1 < qanak)
                    max1 = qanak;
                qanak = 0;
            }
            Console.WriteLine(max1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] b= new int[100000];
            int power;
            int max = 1;
            for(int i=0;i<n;i++)
            {
                power = Convert.ToInt32(a[i]);
                int sqrt=(int)Math.Sqrt(power);
                if(power%2==0)
                {
                    power/=2;
                    b[2]++;
                    if(b[2]>max)
                        max=b[2];
                    while(power%2==0)
                        power/=2;
                }
                for(int j=3;j<=sqrt;j+=2)
                {
                    if(power%j==0)
                    {
                        power/=j;
                        b[j]++;
                        if(b[j]>max)
                            max=b[j];
                        while(power%j==0)
                            power/=j;
                    }
                }
                if(power>1)
                {
                    b[power]++;
                    if(b[power]>max)
                        max=b[power];
                }
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] power = new int[a.Length];
            int max = 0;
            for(int i=0;i<n;i++)
            {
                power[i] = Convert.ToInt32(a[i]);
                if (max < power[i])
                    max = power[i];
            }
            int sqrt = Convert.ToInt32(Math.Sqrt(max));
            int max1 = 1;
            int qanak=0;
            for(int i=2;i<=sqrt;i++)
            {
                for(int j=0;j<n;j++)
                {
                    if (power[j] % i == 0)
                        qanak++;
                }
                if (max1 < qanak)
                    max1 = qanak;
                qanak = 0;
            }
            for (int j = 0; j < n; j++)
            {
                if (power[j] % max == 0)
                    qanak++;
            }
            if (max1 < qanak)
                Console.WriteLine(qanak);
            else
                Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] b= new int[];
            int power;
            int max = 1;
            for(int i=0;i<n;i++)
            {
                power = Convert.ToInt32(a[i]);
                if(power%2==0)
                {
                    power/=2;
                    b[2]++;
                    while(power%2==0)
                        power/=2;
                }
                for(int j=3;power>1;j+=2)
                {
                    if(power%j==0)
                    {
                        power/=j;
                        b[j]++;
                        if(b[j]>max)
                            max=b[j];
                        while(power%j==0)
                            power/=j;
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] power = new int[a.Length];
            int max = 0;
            for(int i=0;i<n;i++)
            {
                power[i] = Convert.ToInt32(a[i]);
                if (max < power[i])
                    max = power[i];
            }
            int sqrt = Convert.ToInt32(Math.Sqrt(max));
            max = 0;
            int qanak=0;
            for(int i=2;i<=sqrt;i++)
            {
                for(int j=0;j<n;j++)
                {
                    if (power[j] % i == 0)
                        qanak++;
                }
                if (max < qanak)
                    max = qanak;
                qanak = 0;
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] power = new int[a.Length];
            int max = 0;
            for(int i=0;i<n;i++)
            {
                power[i] = Convert.ToInt32(a[i]);
                if (max < power[i])
                    max = power[i];
            }
            int sqrt = Convert.ToInt32(Math.Sqrt(max));
            max = 1;
            int qanak=0;
            for(int i=2;i<=sqrt;i++)
            {
                for(int j=0;j<n;j++)
                {
                    if (power[j] % i == 0)
                        qanak++;
                }
                if (max < qanak)
                    max = qanak;
                qanak = 0;
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] b= new int[10000];
            int power;
            int max = 1;
            for(int i=0;i<n;i++)
            {
                power = Convert.ToInt32(a[i]);
                if(power%2==0)
                {
                    power/=2;
                    b[2]++;
                    if(b[2]>max)
                        max=b[2];
                    while(power%2==0)
                        power/=2;
                }
                for(int j=3;power>1;j+=2)
                {
                    if(power%j==0)
                    {
                        power/=j;
                        b[j]++;
                        if(b[j]>max)
                            max=b[j];
                        while(power%j==0)
                            power/=j;
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] b= new int[100000];
            int power;
            int max = 1;
            for(int i=0;i<n;i++)
            {
                power = Convert.ToInt32(a[i]);
                if(power%2==0)
                {
                    power/=2;
                    b[2]++;
                    if(b[2]>max)
                        max=b[2];
                    while(power%2==0)
                        power/=2;
                }
                for(int j=3;power>1;j+=2)
                {
                    if(power%j==0)
                    {
                        power/=j;
                        b[j]++;
                        if(b[j]>max)
                            max=b[j];
                        while(power%j==0)
                            power/=j;
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VanyaAndTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int[] b= new int[10000];
            int power;
            int max = 1;
            for(int i=0;i<n;i++)
            {
                power = Convert.ToInt32(a[i]);
                if(power%2==0)
                {
                    power/=2;
                    b[2]++;
                    while(power%2==0)
                        power/=2;
                }
                for(int j=3;power>1;j+=2)
                {
                    if(power%j==0)
                    {
                        power/=j;
                        b[j]++;
                        if(b[j]>max)
                            max=b[j];
                        while(power%j==0)
                            power/=j;
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}


for i in range(int(input())):
    s=input()
    s=''.join(sorted(s))
    if s[-1]==s[0]:
        print(-1)
    else:
        print(s)


#!/usr/bin/env python
# coding: utf-8

# In[ ]:

for _ in range(int(input())):
    s=input()
    first=s[0]
    l=len(s)
    if s==(first*l):
        print(-1)

    else:
        if s!=s[::-1]:
            print(s)

        else:
            copy=list(s)
            copy[l//2],copy[l//2 +1]=copy[l//2 +1],copy[l//2]
            print(''.join(copy))


#!/usr/bin/env python
# coding: utf-8

# In[ ]:

for _ in range(int(input())):
    s=input()
    first=s[0]
    l=len(s)
    if s==(first*l):
        print(-1)

    else:
        if s!=s[::-1]:
            print(s)

        else:
            f=0
            copy=list(s)
            for i in range(l-1):
                if s[i]!=s[i+1]:
                    f=1
                    copy[i],copy[i+1]=copy[i+1],copy[i]
                    break

            if f==0:
                print(-1)

            else:
                print(''.join(copy))


t=int(input())
for i in range(t):
    n=input()
    c=[]
    count=0
    for i in range(len(n)):
        c.insert(i,n[i])
    m=list(reversed(n))

    if c!=m:
        print(n)
    else:
        for i in range(len(n)-1):
            if n[i]==n[i+1]:
                count+=1
        if count==len(n)-1:
            print("-1")
        else:
            c[len(n)-1],c[len(n)-2]=c[len(n)-2],c[len(n)-1]
            for i in range(len(n)):
                print(c[i],end="")


t=int(input())
for i in range(t):
    n=input()
    c=[]
    count=0
    for i in range(len(n)):
        c.insert(i,n[i])
    m=list(reversed(n))

    if c!=m:
        print(n)
    else:
        for i in range(len(n)-1):
            if n[i]==n[i+1]:
                count+=1
        if count==len(n)-1:
            print("-1")
        else:
            x=c[len(n)-1]
            c.remove(c[len(n)-1])
            c.append(x)
            for i in range(len(n)):
                print(c[i],end="")
            print()


t=int(input())
for i in range(t):
    n=input()
    c=[]
    count=0
    for i in range(len(n)):
        c.insert(i,n[i])
    m=list(reversed(n))

    if c!=m:
        print(n)
    else:
        for i in range(len(n)-1):
            if n[i]==n[i+1]:
                count+=1
        if count==len(n)-1:
            print("-1")
        else:
            c[len(n)-1],c[len(n)-2]=c[len(n)-2],c[len(n)-1]
            for i in range(len(n)):
                print(c[i],end="")
            print()


t=int(input())
for i in range(t):
    n=input()
    c=[]
    count=0
    for i in range(len(n)):
        c.insert(i,n[i])
    m=list(reversed(n))

    if c!=m:
        print(n)
    else:
        for i in range(len(n)-1):
            if n[i]==n[i+1]:
                count+=1
        if count==len(n)-2:
            print("-1")
        else:
            c[len(n)-1],c[len(n)-2]=c[len(n)-2],c[len(n)-1]
            for i in range(len(n)):
                print(c[i],end="")
            print()


def getElements(s):
    dicr = {}
    for i in s:
        if i in dicr:
            dicr[i] = dicr[i] + 1
        else:
            dicr[i] = 1
        return dicr

def isPalindrome(s):
	return s == s.reverse()

def isGood(s):
	if not isPalindrome(s):
	    return s
	else:
	    dict = getElements(s)
	    if len(dict) == 1 :
	        return "-1"
	    else:
	        res = ""
	        for i in dic:
	            res = res + i*dic[i]
	        return res

t = int(input())
for i in range(0,t):
	s = input()
	print(isGood())


def getElements(s):
    dicr = {}
    for i in s:
        if i in dicr:
            dicr[i] = dicr[i] + 1
        else:
            dicr[i] = 1
    return dicr

def isPalindrome(s):
	return s == s.reverse()

def isGood(s):
	if not isPalindrome(s):
	    return s
	else:
	    dict = getElements(s)
	    if len(dict) == 1 :
	        return "-1"
	    else:
	        res = ""
	        for i in dict:
	            res = res + i*dict[i]
	        return res

t = int(input())
for i in range(0,t):
	s = input()
	print(isGood(s))


def isPalindrome(s):
	return s == s.reverse()

def isGood(s):
	return not isPalindrome(s)

t = int(input())
for i in range(0,t):
	s = input()
	if isGood(s):
	    print(s)
	else:
	    print("-1")


def getElements(s):
    dicr = {}
    for i in s:
        if i in dicr:
            dicr[i] = dicr[i] + 1
        else:
            dicr[i] = 1
    return dicr

def isPalindrome(s):
	return s == "".join(reversed(s))

def isGood(s):
	if not isPalindrome(s):
	    return s
	else:
	    dict = getElements(s)
	    if len(dict) == 1 :
	        return "-1"
	    else:
	        res = ""
	        for i in dict:
	            res = res + i*dict[i]
	        return res

t = int(input())
for i in range(0,t):
	s = input()
	print(isGood(s))


t=int(input())
i=0
anss=[]
while i<t:
    i+=1
    s=input()
    count=0
    l=int(len(s)/2)
    ans=100000
    for x in range(l):
        if s[x]==s[-x-1]:
            count+=1
        if s[x]!=s[x+1]:
            ans=x
    print(ans)
    if (count==l)and (ans!=100000):
        v=s[ans]
        k=s[ans+1]
        s=s[:ans]+k+v+s[ans+2:]
        anss.append(s)
    elif (count==l) and (ans==0):
        anss.append(-1)
    else:
        anss.append(s)
for y in anss:
    print(y)


t=int(input())
i=0
anss=[]
while i<t:
    i+=1
    s=input()
    count=0
    l=int(len(s)/2)
    ans=100000
    for x in range(l):
        if s[x]==s[-x-1]:
            count+=1
        if s[x]!=s[x+1]:
            ans=x
    if (count==l)and (ans!=100000):
        v=s[ans]
        k=s[ans+1]
        s=s[:ans]+k+v+s[ans+2:]
        anss.append(s)
    elif (count==l) and (ans==0):
        anss.append(-1)
    else:
        anss.append(s)
for y in anss:
    print(y)


t=int(input())
i=0
anss=[]
while i<t:
    i+=1
    s=input()
    count=0
    l=int(len(s)/2)
    ans=100000
    for x in range(l):
        if s[x]==s[-x-1]:
            count+=1
        if s[x]!=s[x+1]:
            ans=x
    if (count==l)and (ans!=100000):
        v=s[ans]
        k=s[ans+1]
        s=s[:ans]+k+v+s[ans+2:]
        anss.append(s)
    elif (count==l) and (ans==100000):
        anss.append(-1)
    else:
        anss.append(s)
for y in anss:
    print(y)


t=int(input())
i=0
anss=[]
while i<t:
    i+=1
    s=input()
    count=0
    l=int(len(s)/2)
    ans=0
    for x in range(l):
        if s[x]==s[-x-1]:
            count+=1
        if s[x]!=s[x+1]:
            ans=x
    if (count==l) and (ans!=0):
        v=s[ans]
        k=s[ans+1]
        s=s[:ans]+k+v+s[ans+2:]
        anss.append(s)
    elif (count==l) and (ans==0):
        anss.append(-1)
    else:
        anss.append(s)
for y in anss:
    print(y)


n=int(input())
for i in range(n):
    s=input()
    le = len(s)
    if le <= 2 or s.count(s[0]) == le:
        print(-1)
    else:
        l=list(s)
        l.sort()
        print(''.join(l))


n=int(input())
for i in range(n):
    s=input()
    if len(s) <= 2:
        print(-1)
    else:
        l=list(s)
        l.sort()
        print(''.join(l))


n=int(input())
for i in range(n):
    s=input()
    le = len(s)
    if s.count(s[0]) == le:
        print(-1)
    else:
        l=list(s)
        l.sort()
        print(''.join(l))


n=int(input())
for _ in range(n):
    s=input()
    if(len(set(s))==1):
        print('-1')
    else:
        print(''.join(sorted(s)))


n=int(input())
for _ in range(n):
    s=input()
    if(len(set(s))==1):
        print('-1')
    elif(s==s[::-1]):
        print(s[1],end="")
        print(s[0],end="")
        print(s[2:])
    else:
        print(s)


def antipalindrome():
    x=input()
    z=" "
    a=[]
    max=0
    flag=0
    if(len(x)%2!=0):
        y=int((len(x)+1)/2)
    else:
        y=int(len(x)/2)

    for j in range(y):
        if(x[j]!=x[len(x)-j-1]):
            flag=1
            return()
            break
    if(flag==0):
        if(x.count(x[0])==len(x)):
           return(-1)
        else:
            for i in range(len(x)):
               a.append(x[i])
            b=a[0]
            a[0]=a[1]
            a[1]=b
            z=z.join(a)
            z=z.replace(" ","")
            return(z)

print(antipalindrome())


t=int(input())
for i in range(t):
  def antipalindrome():
      x=input()
      z=" "
      a=[]
      flag=0
      if(len(x)%2!=0):
         y=int((len(x)+1)/2)
      else:
         y=int(len(x)/2)

      for j in range(y):
            if(x[j]!=x[len(x)-j-1]):
                flag=1
                return(x)

      if(flag==0):
          if(x.count(x[0])==len(x)):
              return(-1)
          else:
              for i in range(len(x)):
                  a.append(x[i])
              b=a[y-1]
              a[y-1]=a[y-2]
              a[y-2]=b
              z=z.join(a)
              z=z.replace(" ","")
              return(z)
  print(antipalindrome())


n=int(input())
z=""
for i in range(n):
    x=input()
    y=list(x)
    y.sort()
    z=z.join(y)
    if(x[0].count()==len(x)):
        print(-1)

    else:
        print(z)
    y.clear()
    z=""


n=int(input())
z=""
for i in range(n):
    x=input()
    y=list(x)
    y.sort()
    z=z.join(y)
    if(y.count(x[0])==len(x)):
        print(-1)

    else:
        print(z)
    y.clear()
    z=""


n=int(input())
z=""
for i in range(n):
    x=input()
    y=list(x)
    y.sort()
    z=z.join(y)
    if(x==z):
        print(-1)
    else:
        print(z)
    y.clear()
    z=""


t=int(input())
for i in range(t):
  def antipalindrome():
      x=input()
      z=" "
      a=[]
      flag=0
      if(len(x)%2!=0):
         y=int((len(x)+1)/2)
      else:
         y=int(len(x)/2)

      for j in range(y):
            if(x[j]!=x[len(x)-j-1]):
                flag=1
                return(x)

      if(flag==0):
          if(x.count(x[0])==len(x)):
              return(-1)
          else:
              for i in range(len(x)):
                  a.append(x[i])
              b=a[0]
              a[0]=a[1]
              a[1]=b
              z=z.join(a)
              z=z.replace(" ","")
              return(z)
  print(antipalindrome())


t=int(input())
for i in range(t):
    s=input()
    k=list(s)
    k.sort()
    f=0
    for i in range(0,len(s)):
        if (k[i-1]!=k[i]):
           f=1
           break
    if (f==0):
        print(-1)
    else:
        print(''.join(k))


t=int(input())
for i in range(t):
    s=input()
    k=list(s)
    k.sort()
    print(''.join(k))


t=int(input())
for i in range(t):
    s=input()
    k=list(s)
    k.sort()
    f=0
    for i in range(1,len(s)):
        if (k[i-1]!=k[i]):
           f=1
    if (f=1):
        print(-1)
    else:
        print(k)
    print(''.join(k))


t=int(input())
for i in range(t):
    s=input()
    k=list(s)
    k.sort()
    f=0
    for i in range(0,len(s)):
        if (k[i-1]==k[i]):
           f=1
           break
    if (f!=0):
        print(-1)
    else:
        print(''.join(k))


t=int(input())
for i in range(t):
    s=input()
    k=list(s)
    f=0
    for i in range(0,len(s)):
        if (k[i-1]!=k[i]):
           f=1
           break
    if (f==0):
        print(-1)
    else:
        print(''.join(k))


def a(l):
    return(l[::-1])
t=int(input())
for i in range(t):
    s=input()
    s=list(s)
    if len(s)%2==0:
        if s[:len(s)//2]==a(s[len(s)//2:]):
            y=0
            for j in range(len(s)-1):
                if s[j]!=s[j+1]:
                    s[j]=s[j+1]
                    y=1
                    for w in range(len(s)):
                        print(s[w],end="")
                    print("")
                    break
            if y==0:
                print("-1")
        else:
            for w in range(len(s)):
                print(s[w],end="")
            print("")

    else:
        if s[:len(s)//2]==a(s[(len(s)//2)+1:]):
            y=0
            for j in range(len(s)-1):
                if s[j]!=s[j+1]:
                    s[j]=s[j+1]
                    y=1
                    for w in range(len(s)):
                        print(s[w],end="")
                    print("")
                    break
            if y==0:
                print("-1")
        else:
            for w in range(len(s)):
                print(s[w],end="")
            print("")


def a(l):
    return(l[::-1])
t=int(input())
for i in range(t):
    s=input()
    s=list(s)
    if len(s)%2==0:
        if s[:len(s)//2]==a(s[len(s)//2:]):
            y=0
            for j in range(len(s)-1):
                if s[j]!=s[j+1]:
                    o=s[j]
                    s[j]=s[j+1]
                    s[j+1]=o
                    y=1
                    for w in range(len(s)):
                        print(s[w],end="")
                    print("")
                    break
            if y==0:
                print("-1")
        else:
            for w in range(len(s)):
                print(s[w],end="")
            print("")

    else:
        if s[:len(s)//2]==a(s[(len(s)//2)+1:]):
            y=0
            for j in range(len(s)-1):
                if s[j]!=s[j+1]:
                    o=s[j]
                    s[j]=s[j+1]
                    s[j+1]=o
                    y=1
                    for w in range(len(s)):
                        print(s[w],end="")
                    print("")
                    break
            if y==0:
                print("-1")
        else:
            for w in range(len(s)):
                print(s[w],end="")
            print("")


t = int(input())
for x in range(t):
    phrase = input()
    letterdict = {}
    letterlist = []
    for y in phrase:
        if(y not in letterdict):
            letterdict[y] = 1
            letterlist += y
        else:
            letterdict[y] += 1
    if(len(letterdict) < 2):
        print(-1)
    else:
        result = ""
        for y in range(len(letterlist)):
            for z in range(letterdict[letterlist[y]]):
                result += letterlist[y]
        print(result)


t = int(input())
for x in range(t):
    phrase = input()
    letterdict = {}
    for y in phrase:
        if(y not in letterdict):
            letterdict[y] = 1
        else:
            letterdict[y] += 1
    if(len(letterdict) < 2):
        print(-1)
    else:
        letterlist = letterdict.keys()
        result = ""
        for y in range(len(letterdict)):
            printletter = letterdict.popitem
            for z in range(letterdict[y]):
                result += letterlist[y]
        print(result)


t = int(input())
for x in range(t):
    phrase = input()
    letterdict = {}
    for y in phrase:
        if(phrase[y] not in letterdict):
            letterdict[phrase[y]] = 1
        else:
            letterdict[phrase[y]] += 1
    if(len(letterdict) < 2):
        print(-1)
    else:
        letterlist = letterdict.keys()
        result = ""
        for y in range(len(letterdict)):
            printletter = letterdict.popitem
            for z in range(letterdict[y]):
                result += letterlist[y]
        print(result)


"""
In python strings don't need indexing in majority of cases.
And that's pythonic way.
"""
for t in range(int(input())):
    value = input()

    if value == len(value) * value[0]:
        print(-1)
    else:
        print(value)


for t in range(int(input())):
    value = input()
    flag = True

    for index in range(1, len(value)):
        if value[0] != value[index]:
            flag = False

    if flag:
        print(-1)
    else:
        print(value[1] + value[0] + value[2:])


"""
In python strings don't need indexing in majority of cases.
And that's pythonic way.
"""
for t in range(int(input())):
    value = input()
    z = sorted([v for v in value])
    if z[0] == z[-1]:
        print(-1)
    else:
        print(z)


"""
In python strings don't need indexing in majority of cases.
And that's pythonic way.
"""
for t in range(int(input())):
    value = input()
    is_pal = value.find(value[::-1])
    if is_pal == 0:
        if value == len(value) * value[0]:
            print(-1)
        else:
            print(value[1]+value[0]+value[2:])
    else:
        print(value)


"""
In python strings don't need indexing in majority of cases.
And that's pythonic way.
"""
for t in range(int(input())):
    value = input()
    z = sorted([v for v in value])
    if z[0] == z[-1]:
        print(-1)
    else:
        print(''.join(z))


n = int(input())
for i in range(n):
    a = input()
    if len(set(a))==1:
        print(-1)
    else:
        print(sorted(a))


n = int(input())
c =''
f = ''
d =''
for i in range(n):
    k = 0
    a = input()
    c = a
    for p in range(len(a)):
        d +=a[0]
#     print(d)
#     print(a)
    if d == a:
        k+=1
        print(-1)
#     print(k)
    if a == a[::-1]:
        for j in range(len(a)-1):
            if k!=0:
                break
                break
            while c==a[::-1]:

                f = a[j]
                a = a[j+1]+a[j+1:]
#                 print(a)

    if a!=a[::-1] :
        print(a)


n = int(input())
for i in range(n):
    a = input()
    if len(set(a))==1:
        print(-1)
    else:
        a = ''.join(sorted(a))
        print(a)


n = int(input())
c =''
f = ''
d =''
for i in range(n):
    k = 0
    a = input()
    c = a
    for p in range(len(a)):
        d +=a[0]
#     print(d)
#     print(a)
    if d == a:
        k+=1
        print(-1)
#     print(k)
    if a == a[::-1]:
        for j in range(len(a)-1):
            if k!=0:
                break
                break
            while c==a[::-1]:

                f = a[j]
                a = a[j+1]+f+a[j+2:]
#                 print(a)

    if a!=a[::-1] :
        print(a)


n = int(input())
for i in range(n):
	a = input()
	if len(set(a))==1:
		print(-1)
	else:print(a)


n = int(input())
for i in range(n):
	a = list(input())
	if len(set(a))==1:
		print(-1)
	else:
		b = sorted(a)
		print("".join(b))


for i in range(int(input())):
    s = input()
    t = set(s)
    ans = ""
    if len(t)==1:
        print(-1)
    else:
        for i in t:
            a = a+ i*(s.count(i))
    print(a)


for j in range(int(input())):
    s = input()
    t = set(s)
    a = ""
    if len(t)==1:
        print(-1)
    else:
        for i in t:
            a = a+ i*(s.count(i))
        print(a)


for j in range(int(input())):
    s = input()
    t = set(s)
    ans = ""
    if len(t)==1:
        print(-1)
    else:
        for i in t:
            a = a+ i*(s.count(i))
        print(a)


for i in range(int(input())):
    s = input()
    t = set(s)
    ans = ""
    if len(t)==1:
        print(-1)
    else:
        for i in t:
            a = a+ i*(s.count(i))
        print(a)


for _ in range(int(input())):
    s = list(input())
    print(-1 if s[1:]==s[:-1] else ''.join(map(str, sorted(s))))


for _ in range(int(input())):
    s = list(input())
    print(-1 if s[1]==s[:-1] else ''.join(map(str, sorted(s))))


t = int(input())
while(t>0):
    s = input()
    news=""
    flag=0
    flag2=0
    if(len(s)==1 or len(s)==2):
        print(-1)
    elif(s!=s[::-1]):
        print(s)
    else:
        for i in range(0,len(s)):
            if flag==0 and s[i]!= 'a':
                if(i!=(len(s)-1) and s[i+1]!=s[i]):
                    ch = s[i]
                    news= news + s[i+1]
                    news+=ch
                    flag=1
                    flag2=1
                else:
                    news+=s[i]
            else:
                if(flag2==0):
                    news+=s[i]
                flag2=0
        if(news==s):
            print(-1)
        else:
            print(news)
    t-=1


t = int(input())
while(t>0):
    s = input()
    news=""
    flag=0
    flag2=0
    if(len(s)==1 or len(s)==2):
        print(-1)
    elif(s!=s[::-1]):
        print(s)
    else:
        for i in range(0,len(s)):
            if flag==0 and s[i]!= 'a':
                ch = s[i]
                news= news + s[i+1]
                news+=ch
                flag=1
                flag2=1
            else:
                if(flag2==0):
                    news+=s[i]
                flag2=0
        if(news==s):
            print(-1)
        else:
            print(news)
    t-=1


t = int(input())
while(t>0):
    s = input()
    news=""
    flag=0
    flag2=0
    if(len(s)==1 or len(s)==2):
        print(-1)
    elif(s!=s[::-1]):
        print(s)
    else:
        for i in range(0,len(s)):
            if flag==0 and s[i]!= 'a':
                ch = s[i]
                news= news + s[i+1]
                news+=ch
                flag=1
                flag2=1
            else:
                if(flag2==0):
                    news+=s[i]
                flag2=0
        print(news)
    t-=1


t = int(input())
while(t>0):
    s = input()
    news=""
    flag=0
    if(len(s)==1 or len(s)==2):
        print(-1)
    elif(s!=s[::-1]):
        print(s)
    else:
        for i in range(0,len(s)):
            if flag==0 and s[i]!= 'a':
                ch = s[i]
                news= news + s[i+1]
                news+=ch
                i+=1
                flag=1
            else:
                news+=s[i]
        print(news)
    t-=1


t = int(input())
while(t>0):
    s = input()
    news=""
    flag=0
    flag2=0
    if(len(s)==1):
        print(-1)
    elif(s!=s[::-1]):
        print(s)
    else:
        for i in range(0,len(s)):
            if flag==0 and s[i]!= 'a':
                if(i!=(len(s)-1) and s[i+1]!=s[i]):
                    ch = s[i]
                    news= news + s[i+1]
                    news+=ch
                    flag=1
                    flag2=1
                else:
                    news+=s[i]
            else:
                if(flag2==0):
                    news+=s[i]
                flag2=0
        if(news==s):
            print(-1)
        else:
            print(news)
    t-=1


#!/bin/python3

import math
import os
import random
import re
#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
    #fptr = open(os.environ['OUTPUT_PATH'], 'w')

    TC = int(input())
    #print (TC)
    for i in range(0,TC):
        #list1 = []
        list2 = (list(input().strip()))
        list1 =sorted(list2)
        n = len(list1)
        p1 =0
        p2 = n -1
        flag = 0
        if n > 1:
            while p1 < n and p2 > 0 and p1 < p2 and p1 < n+1:
                if list1[p1] == list1[p2] :
                    p1 = p1 + 1
                    p2 =p2 -1
                    flag = 2
                else:
                    flag = 1
                    break
        else : flag = 2
        #flag = 2
        str1 =''
        if flag == 1: print (str1.join((list1)))
        elif flag ==2 : print (-1)


#!/bin/python3

import math
import os
import random
import re
#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
    #fptr = open(os.environ['OUTPUT_PATH'], 'w')

    TC = int(input())
    #print (TC)
    for i in range(0,TC):
        #list1 = []
        list1 = (list(input().strip()))
        n = len(list1)
        p1 =0
        p2 = n -1
        flag = 0
        while p1 < n and p2 > 0 and p1 < p2 :
            if list1[p1] == list1[p2] :
                p1 = p1 + 1
                p2 =p2 -1
            else:
                flag = 1
                break
        str1 =''
        if flag == 1: print (str1.join(sorted(list1)))
        else : print (-1)


#!/bin/python3

import math
import os
import random
import re
#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
    #fptr = open(os.environ['OUTPUT_PATH'], 'w')

    TC = int(input())
    #print (TC)
    for i in range(0,TC):
        #list1 = []
        list2 = (list(input().strip()))
        list1 =sorted(list2)
        n = len(list1)
        p1 =0
        p2 = n -1
        flag = 0
        while p1 < n and p2 > 0 and p1 < p2 and p1 < n+1:
            if list1[p1] == list1[p2] :
                p1 = p1 + 1
                p2 =p2 -1
                flag = 2
            else:
                flag = 1
                break
        #flag = 2
        str1 =''
        if flag == 1: print (str1.join((list1)))
        elif flag ==2 : print (-1)


#!/bin/python3

import math
import os
import random
import re
#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
    #fptr = open(os.environ['OUTPUT_PATH'], 'w')

    TC = int(input())
    #print (TC)
    for i in range(0,TC):
        #list1 = []
        list1 = (list(input().strip()))
        n = len(list1)
        p1 =0
        p2 = n -1
        flag = 0
        while p1 < n and p2 > 0 and p1 < p2 :
            if list1[p1] == list1[p2] :
                p1 = p1 + 1
                p2 =p2 -1
            else:
                flag = 1
                break
        str1 =''
        if flag == 1: print (str1.join(list1))
        else : print (-1)


def swap(s, i, j):
    tmp = s[i]
    s[i] = s[j]
    s[j] = tmp
    return s

def is_synmetric(s):
    n = len(s)

    flag = True
    for i in range(n):
        if s[i] != s[-(i+1)]:
            flag = False
            break
    return flag

def main(s):
    n = len(s)

    if s.count(s[0]) == n:
        return [str(-1)]

    if not is_synmetric(s):
        return s

    elm1 = s[0]
    for i in range(1, n//2):
        if s[i] != elm1:
            out_s = swap(s, 0, i)
            break

    return out_s

t = int(input())

for i in range(t):
    s = list(input())
    out = main(s)
    print("".join(out))


def swap(s, i, j):
    tmp = s[i]
    s[i] = s[j]
    s[j] = tmp
    return s

#def is_synmetric(s):
#    n = len(s)
#
#    flag = True
#    for i in range(n):
#        if s[i] != s[-(i+1)]:
#            flag = False
#            break
#    return flag

def main(s):
    n = len(s)

    if s.count(s[0]) == n:
        return [str(-1)]

    #if not is_synmetric(s):
    #    return s

    synm = True
    elm1 = s[0]
    for i in range(0, n//2+1):
        if s[i] != s[-(i+1)]:
            synm = False
            return s

        if s[i] != elm1:
            out_s = swap(s, 0, i)
            break

    return out_s

t = int(input())

for i in range(t):
    s = list(input())
    out = main(s)
    print("".join(out))


def swap(s, i, j):
    tmp = s[i]
    s[i] = s[j]
    s[j] = tmp
    return s

#def is_synmetric(s):
#    n = len(s)
#
#    flag = True
#    for i in range(n):
#        if s[i] != s[-(i+1)]:
#            flag = False
#            break
#    return flag

def main(s):
    n = len(s)

    if s.count(s[0]) == n:
        return [str(-1)]

    #if not is_synmetric(s):
    #    return s

    synm = True
    elm1 = s[0]
    for i in range(0, n//2):
        if s[i] != s[-(i+1)]:
            synm = False
            return s

        if s[i] != elm1:
            out_s = swap(s, 0, i)
            break

    return out_s

t = int(input())

for i in range(t):
    s = list(input())
    out = main(s)
    print("".join(out))


def is_palindrome(l, mid, s):

    i, j = 0, l-1
    while i <= mid <= j:
        if s[i] != s[j]:
            return False
        i += 1
        j -= 1
    return True

def solve(s):
    l = len(s)
    mid = l // 2

    arr = list(s)
    found = False
    for i in range(mid, -1, -1):
        temp = arr[i]
        arr[i] = arr[mid]
        arr[mid] = temp
        if not is_palindrome(l, mid, arr):
            print("".join(arr))
            found = True
            break
        arr = list(s)

    if not found:
        print(-1)

def main():
    q = int(input())

    for i in range(q):
        s = input()
        solve(s)

if __name__ == '__main__':
    main()


def is_palindrome(l, mid, s):

    i, j = 0, l-1
    while i <= mid <= j:
        if s[i] != s[j]:
            return False
        i += 1
        j -= 1
    return True

def solve(s):
    l = len(s)
    mid = l // 2

    c = s.count(s[0])
    if c == l:
        print(-1)
        return
    else:
        arr = list(s)
        found = False
        for i in range(mid, -1, -1):
            temp = arr[i]
            arr[i] = arr[mid]
            arr[mid] = temp
            if not is_palindrome(l, mid, arr):
                print("".join(arr))
                found = True
                break
            arr = list(s)

        if not found:
            print(-1)

def main():
    q = int(input())

    for i in range(q):
        s = input()
        solve(s)

if __name__ == '__main__':
    main()


def getTwoHalves(s):
    lS, rS = s[:len(s) // 2], ""

    if len(s) % 2 == 0:
        rS = s[len(s) // 2:]
    else:
        rS = s[len(s) // 2 + 1:]

    return lS, rS

n = int(input())

for i in range(n):
    s = input()

    if len(s) == 1:
        print(-1)
    else:
        ans = getTwoHalves(s)
        if ans[0] == ans[1]:
            s = ''.join(sorted(s))
            ans = getTwoHalves(s)
            if ans[0] == ans[1]:
                print(-1)
            else:
                print(str(s))
        else:
            print(s)


for i in range(int(input())):
	q=input()
	s=sorted(q)
	a=0
	for i in range (len(s)-1):
		if s[i]!=s[i+1]:
			a=1
	if a==0:
		print(-1)
	else:
		ans=''
		for i in range(len(s)):
			ans+=s[i]
		print(ans)


for i in range(int(input())):
	q=input()
	s=sorted(a)
	a=0
	for i in range (len(s)-1):
		if s[i]!=s[i+1]:
			a=1
	if a==0:
		print(-1)
	else:
		print(q)


for i in range(int(input())):
	a=input()
	s=sorted(a)
	a=0
	for i in range (len(s)-1):
		if s[i]!=s[i+1]:
			a=1
	if a==0:
		print(-1)
	else:
		print(a)


for i in range(int(input())):
	s=sorted(input())
	a=0
	for i in range (len(s-1)):
		if s[i]!=s[i+1]:
			a=1
	if a==0:
		print(-1)
	else:
		print(s)


for i in range(int(input())):
	q=input()
	s=sorted(q)
	a=0
	for i in range (len(s)-1):
		if s[i]!=s[i+1]:
			a=1
	if a==0:
		print(-1)
	else:
		print(q)


for i in range(int(input())):
	s=sorted(input())
	a=0
	for i in range (len(s)):
		if s[i]!=s[i+1]:
			a=1
	if a==0:
		print(-1)
	else:
		print(s)


for _ in range(int(input())):
    s=input()
    if s!=s[::-1]:
        print(s)
    else:
        l=[ifor i in s]
        print(''.join(sorted(l)))


for _ in range(int(input())):
    s=input()
    if s!=s[::-1]:
        print(s)
    else:
        l=[i for i in s]
        n=len(s)//2
        for i in range(n,0,-1):
            if l[n]!=l[n-1]:
                l[n], l[n-1] = l[n-1], l[n]
                break
        if s==''.join(l):
            print(-1)

        else:
            print(''.join(l))


for _ in range(int(input())):
    s=input()
    if s!=s[::-1]:
        print(s)
    else:
        l=[i for i in s]
        s1=''.join(sorted(l))
        if s1==s1[::-1]:
            print(-1)
        else:
            print(s1)


for _ in range(int(input())):
    s=input()
    if s!=s[::-1]:
        print(s)
    else:
        l=[i for i in s]
        print(''.join(sorted(l)))


for _ in range(int(input())):
    s=input()
    if s!=s[::-1]:
        print(s)
    else:
        l=[i for i in s]
        n=len(s)//2
        for i in range(n,0,-1):
            if l[n]!=l[n-1]:
                l[n], l[n-1] = l[n-1], l[n]
                break
        if s==''.join(l):
            print(-1)
        else:
            print(''.join(l))


for _ in range(int(input())):
	n = input()
	if n != n[::-1]:print(n)
	elif len(n) == 1:print(-1)
	elif all(x == n[0] for x in n):print(-1)
	elif n==n[::-1]and len(n)>2:print(n[1:] + n[0])


for _ in range(int(input())):
	n = input()
	if n != n[::-1]:print(n)
	elif len(n) == 1:print(-1)
	elif n == n[::-1] and len(n) == 2:print(-1)
	elif n == n[::-1] and len(n) > 2:print(n[1:] + n[0])


from collections import Counter
t=int(input())
for _ in range(t):
    s=input()
    n=len(s)
    a=Counter(s)
    for val in a:
        if s.index(val)==n-1:
            s=s[-1]+s[:-1]
        elif s.index(val)==0:
            s=s[1:]+s[0]
        else:
            s=s[:s.index(val)]+s[s.index(val)+1:]+val
    if s==s[::-1]:
        print(-1)
    else:
        print(s)


from collections import Counter
t=int(input())
for _ in range(t):
    s=input()
    n=len(s)
    a=Counter(s)
    for val in a:
        if s.index(val)==n-1:
            s=s[-1]+s[:-1]
        elif s.index(val)==0:
            s=s[1:]+s[0]
        else:
            s=s[:s.index(val)]+s[s.index(val)+1:]+val
        break
    if s==s[::-1]:
        print(-1)
    else:
        print(s)


from collections import Counter
t=int(input())
for _ in range(t):
    s=input()
    n=len(s)
    a=Counter(s)
    for val in a:
        temp=val

    if s.index(temp)==n-1:
        s=s[-1]+s[:-1]
    elif s.index(temp)==0:
        s=s[1:]+s[0]
    else:
        s=s[:s.index(temp)]+s[s.index(temp)+1:]+temp

    if s==s[::-1]:
        print(-1)
    else:
        print(s)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
        continue
    if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
        print(s[1] + s[3] + s[2:])
        continue
    if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
        print(s[1] + s[3] + s[2:])
        continue
    print(s)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
        continue
    if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
        print(s[1] + s[0] + s[2:])
        continue
    if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
        print(s[1] + s[0] + s[2:])
        continue
    print(s)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
    else:
        k = s[2]
        ss = s[1] + s[0] + s[2:]
        print(ss)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
        continue
    if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
        print(s[1] + s[len(s)//2 - 1] + s[2:])
        continue
    if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
        print(s[1] + s[len(s)//2 - 1] + s[2:])
        continue
    print(s)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
        continue
    if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
        print(s[0:len(s) // 2 + 1] + s[len(s) // 2:])
        continue
    if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
        print(s[0:len(s) // 2] + s[len(s) // 2:])
        continue
    print(s)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
        continue
    if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
        print(sorted(s))
        continue
    if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
        print(sorted(s))
        continue
    print(s)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
        continue
    if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
        print(s[len(s) // 2:] + s[0:len(s) // 2])
        continue
    if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
        print(s[len(s) // 2:] + s[0:len(s) // 2])
        continue
    print(s)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
        continue
    if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
        print(''.join(sorted(s)))
        continue
    if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
        print(''.join(sorted(s)))
        continue
    print(s)


t = int(input())

for i in range(t):
    s = str(input())
    dif = 0
    for j in range(97, 123):
        if chr(j) in s:
            dif += 1
    if dif == 1:
        print(-1)
        continue
    if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
        print(s[0:len(s) // 2] + s[len(s) // 2:])
        continue
    if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
        print(s[0:len(s) // 2] + s[len(s) // 2:])
        continue
    print(s)


def palin(s):
    n=len(s)
    i=0
    while i<n/2:
        if s[i]!=s[n-1-i]: return False
        else: pass
        i+=1
    return True

n=int(input())
l=[]
for i in range(n):
    s=input()
    if not(palin(s)):
        l.append(s)
    else:
        if len(set([x for x in s]))<=1:
            l.append('-1')
        else:
            s1=s[1]+s[0]+s[2:]
            l.append(s1)
for k in l:
    print(k)


def palin(s):
    n=len(s)
    i=0
    while i<n/2:
        if s[i]!=s[n-1-i]: return False
        else: pass
        i+=1
    return True

def make_good(s):
    for i in range(len(s)-2):
        s1=s[0:i]+s[i+1]+s[i]+s[i+2:]
        if not(palin(s1)):
            return s1

n=int(input())
l=[]
for i in range(n):
    s=input()
    if not(palin(s)):
        l.append(s)
    else:
        if len(set([x for x in s]))<=1:
            l.append('-1')
        else:
            l1=[x for x in s]
            l1.sort()
            s=''.join(l1)
            l.append(s)
for k in l:
    print(k)


def palin(s):
    n=len(s)
    i=0
    while i<n/2:
        if s[i]!=s[n-1-i]: return False
        else: pass
        i+=1
    return True

def make_good(s):
    for i in range(len(s)-2):
        s1=s[0:i]+s[i+1]+s[i]+s[i+2:]
        if not(palin(s1)):
            return s1

n=int(input())
l=[]
for i in range(n):
    s=input()
    if not(palin(s)):
        l.append(s)
    else:
        if len(set([x for x in s]))<=1:
            l.append('-1')
        else:
            s=make_good(s)
            l.append(s)
for k in l:
    print(k)


def goodstr(s):
    n=len(s)
    if s.count(s[0])==n:
        return -1
    elif s!=s[::-1]:
        return s
    else:
        m=n//2
        j=m+1
        while s[m]==s[j]:
            j+=1
        return s[:m]+s[j]+s[m+1:j]+s[m]+s[j+1:]

for i in range(int(input())):
    print(goodstr(input()))


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/**
 * Created by himanshubhardwaj on 02/09/18.
 */
public class C {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
//        int dp[][] = new int[n][4];
        int dp[] = new int[n];
        String a = br.readLine();
        String b = br.readLine();

//
//        dp[0][0] = (a.charAt(0) == b.charAt(0)) ? 0 : Integer.MAX_VALUE;
//        dp[0][1] = (a.charAt(0) == b.charAt(0)) ? Integer.MAX_VALUE : 1;
//        dp[0][2] = Integer.MAX_VALUE;
//        dp[0][3] = Integer.MAX_VALUE;
//
//        if (n == 1) {
//            int k = Integer.MAX_VALUE;
//
//            for (int i = 0; i < 4; i++) {
//                k = Math.min(k, dp[0][i]);
//            }
//            System.out.println(k);
//            return;
//        }
//
//        dp[1][0] = (a.charAt(0) == b.charAt(0)) ? 0 : Integer.MAX_VALUE;
//        dp[1][1] = (a.charAt(0) == b.charAt(0)) ? Integer.MAX_VALUE : 1;
//        dp[1][2] = Integer.MAX_VALUE;
//        dp[1][3] = Integer.MAX_VALUE;

        dp[0] = (a.charAt(0) == b.charAt(0)) ? 0 : 1;
        if (n == 1) {
            System.out.println(dp[0]);
            return;
        }
//        dp[1] = (a.charAt(1) == b.charAt(1)) ?
//                dp[0] :
//                (((int) a.charAt(0) + a.charAt(1)) == ((int) b.charAt(0) + b.charAt(1))) ? dp[0] : (1 + dp[0]);
//
//
//        if (n == 2) {
//            System.out.println(dp[1]);
//            return;
//        }

        for (int i = 1; i < n; i++) {
            if (a.charAt(i) == b.charAt(i)) {
                dp[i] = dp[i - 1];
            } else {
                if (a.charAt(i - 1) == b.charAt(i - 1)) {
                    dp[i] = dp[i - 1] + 1;
                } else {
                    if (((int) a.charAt(i - 1) + a.charAt(i)) == ((int) b.charAt(i - 1) + b.charAt(i))) {
                        dp[i] = dp[i - 1];
                    } else {
                        dp[i] = dp[i - 1] + 1;
                    }
                }
            }
        }

        System.out.println(dp[n - 1]);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by himanshubhardwaj on 02/09/18.
 */
public class C {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
//        int dp[][] = new int[n][4];
        int dp[] = new int[n];
        String a = br.readLine();
        String b = br.readLine();

//
//        dp[0][0] = (a.charAt(0) == b.charAt(0)) ? 0 : Integer.MAX_VALUE;
//        dp[0][1] = (a.charAt(0) == b.charAt(0)) ? Integer.MAX_VALUE : 1;
//        dp[0][2] = Integer.MAX_VALUE;
//        dp[0][3] = Integer.MAX_VALUE;
//
//        if (n == 1) {
//            int k = Integer.MAX_VALUE;
//
//            for (int i = 0; i < 4; i++) {
//                k = Math.min(k, dp[0][i]);
//            }
//            System.out.println(k);
//            return;
//        }
//
//        dp[1][0] = (a.charAt(0) == b.charAt(0)) ? 0 : Integer.MAX_VALUE;
//        dp[1][1] = (a.charAt(0) == b.charAt(0)) ? Integer.MAX_VALUE : 1;
//        dp[1][2] = Integer.MAX_VALUE;
//        dp[1][3] = Integer.MAX_VALUE;

        dp[0] = (a.charAt(0) == b.charAt(0)) ? 0 : 1;
        if (n == 1) {
            System.out.print(dp[0]);
            return;
        }
//        dp[1] = (a.charAt(1) == b.charAt(1)) ?
//                dp[0] :
//                (((int) a.charAt(0) + a.charAt(1)) == ((int) b.charAt(0) + b.charAt(1))) ? dp[0] : (1 + dp[0]);
//
//
//        if (n == 2) {
//            System.out.println(dp[1]);
//            return;
//        }

        for (int i = 1; i < n; i++) {
            if (a.charAt(i) == b.charAt(i)) {
                dp[i] = dp[i - 1];
            } else {
                if (a.charAt(i - 1) == b.charAt(i - 1)) {
                    dp[i] = dp[i - 1] + 1;
                } else {
                    if (((int) a.charAt(i - 1) + (int)a.charAt(i)) == ((int) b.charAt(i - 1) + (int)b.charAt(i))) {
                        dp[i] = dp[i - 1];
                    } else {
                        dp[i] = dp[i - 1] + 1;
                    }
                }
            }
        }

        System.out.print(dp[n - 1]);
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String str=sc.next();
		String s=sc.next();
		char[] arr=str.toCharArray();
		char[] a=s.toCharArray();
		int ans=0;
		for(int i=0;i<n;i++) {
			if(arr[i]==a[i])continue;
			else if(i==n-1){
				arr[i]=a[i];
				ans++;
			}else if(arr[i+1]!=a[i]) {
				arr[i]=a[i];
				ans++;
			}else if(arr[i+1]==a[i]) {
				char temp=arr[i+1];
				arr[i+1]=arr[i];
				arr[i]=temp;
				ans++;
			}
		}
		System.out.println(ans);
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String str=sc.next();
		String s=sc.next();
		char[] arr=str.toCharArray();
		char[] a=s.toCharArray();
		int ans=0;
		for(int i=0;i<n;i++) {
			if(arr[i]==a[i])continue;
			else if(i==n-1){
				arr[i]=a[i];
				ans++;
			}else if(arr[i+1]!=a[i]) {
				arr[i]=a[i];
				ans++;
			}else if(arr[i+1]==a[i]&&arr[i+1]!=a[i+1]) {
				char temp=arr[i+1];
				arr[i+1]=arr[i];
				arr[i]=temp;
				ans++;
			}else {
				arr[i]=a[i];
				ans++;
			}
		}
		System.out.println(ans);
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String str=sc.next();
		String s=sc.next();
		int x=0,y=0;
		for(int i=0;i<n;i++) {
			if(str.charAt(i)=='1')x=x+i;
			if(s.charAt(i)=='1')y=y+i;
		}
		System.out.println(Math.abs(x-y));
	}
}


/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.

*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
        */
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        char[] a = br.readLine().toCharArray();
        char[] b = br.readLine().toCharArray();

        int prevIndex = -1;
        int count=0;
        for(int i=0;i<n;i++){
            if(a[i]!= b[i]){
                count++;
                if( i+1<n && a[i+1]!=a[i])  i++;
            }
        }
        System.out.println(count);
    }
}


/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
*/
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        char[] a = br.readLine().toCharArray();
        char[] b = br.readLine().toCharArray();

        int ans1=0;
        int ans2=0;
        for(int i=0;i+1<n;i+=2){
            if(a[i]==b[i] && a[i+1]!=b[i+1]) ans1+=1;
            else if(a[i]!=b[i] && a[i+1]==b[i+1])   ans1+=1;
            else if(a[i]!=b[i]  && a[i+1]!= b[i+1] && a[i]!=a[i+1]) ans1+=1;
            else if(a[i]!=b[i]  && a[i+1]!= b[i+1] )    ans1+=2;
        }
        for(int i=n-1;i-1>=0;i-=2){
            if(a[i]==b[i] && a[i-1]!=b[i-1]) ans2+=1;
            else if(a[i]!=b[i] && a[i-1]==b[i-1])   ans2+=1;
            else if(a[i]!=b[i]  && a[i-1]!= b[i-1] && a[i]!=a[i-1]) ans2+=1;
            else if(a[i]!=b[i]  && a[i-1]!= b[i-1] )    ans2+=2;
        }

        if(n%2 !=0){
            if(a[n-1]!=b[n-1])  ans1++;
            if(a[0]!=b[0])  ans2++;
        }

        System.out.println(Math.min(ans1, ans2));
    }
}


/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
*/
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        char[] a = br.readLine().toCharArray();
        char[] b = br.readLine().toCharArray();

        int ans=0;
        for(int i=0;i+1<n;i+=2){
            if(a[i]==b[i] && a[i+1]!=b[i+1]) ans+=1;
            else if(a[i]!=b[i] && a[i+1]==b[i+1])   ans+=1;
            else if(a[i]!=b[i]  && a[i+1]!= b[i+1] && a[i]!=a[i+1]) ans+=1;
            else if(a[i]!=b[i]  && a[i+1]!= b[i+1] )    ans+=2;
        }

        if(n%2 !=0){
            if(a[n-1]!=b[n-1])  ans++;
        }

        System.out.println(ans);
    }
}


import java.util.*;

public class CF_1037C {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s1=sc.next();
		String s2=sc.next();
		int pnlty=0;
		char[] ch1=s1.toCharArray();
		char[] ch2=s2.toCharArray();
		int[] i1=new int[n];
		int[] i2=new int[n];
		for(int i=0;i<n;i++) {
			i1[i]=(int)ch1[i];
			i2[i]=(int)ch2[i];
		}
		int[] dif=new int[n];
		for(int i=0;i<n;i++) {
			dif[i]=i1[i]^i2[i];
		}
		for(int i=0;i<n;i++) {
			int flag=0;
			if(dif[i]==1) {
				for(int j=i+1;j<i+2 && j<n;j++) {
					if(dif[i]==dif[j] && i1[i]!=i1[j]) {
						pnlty+=j-i;
						flag=1;
						dif[j]=0;
					}
				}
				if(flag==0) {
					pnlty+=1;
				}
			}
		}
		System.out.println(pnlty);
	}
}


import java.util.*;

public class CF_1037C {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s1=sc.next();
		String s2=sc.next();
		int pnlty=0;
		char[] ch1=s1.toCharArray();
		char[] ch2=s2.toCharArray();
		int[] i1=new int[n];
		int[] i2=new int[n];
		for(int i=0;i<n;i++) {
			i1[i]=(int)ch1[i];
			i2[i]=(int)ch2[i];
		}
		int[] dif=new int[n];
		for(int i=0;i<n;i++) {
			dif[i]=i1[i]^i2[i];
		}
		for(int i=0;i<n;i++) {
			int flag=0;
			if(dif[i]==1) {
				for(int j=i+1;j<j+2 && j<n;j++) {
					if(dif[i]==dif[j]) {
						pnlty+=j-i;
						flag=1;
						dif[j]=0;
						break;
					}
				}
				if(flag==0) {
					pnlty+=1;
				}
			}
		}
		System.out.println(pnlty);
	}
}


import java.util.*;

public class CF_1037C {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s1=sc.next();
		String s2=sc.next();
		int pnlty=0;
		char[] ch1=s1.toCharArray();
		char[] ch2=s2.toCharArray();
		int[] i1=new int[n];
		int[] i2=new int[n];
		for(int i=0;i<n;i++) {
			i1[i]=(int)ch1[i];
			i2[i]=(int)ch2[i];
		}
		int[] dif=new int[n];
		for(int i=0;i<n;i++) {
			dif[i]=i1[i]^i2[i];
		}
		for(int i=0;i<n;i++) {
			int flag=0;
			if(dif[i]==1) {
				for(int j=i+1;j<i+2 && j<n;j++) {
					if(dif[i]==dif[j]) {
						pnlty+=j-i;
						flag=1;
						dif[j]=0;
					}
				}
				if(flag==0) {
					pnlty+=1;
				}
			}
		}
		System.out.println(pnlty);
	}
}


import java.util.*;
public class A
{
      public static void main(String ar[])
      {
            Scanner s=new Scanner(System.in);
            int n=s.nextInt();  s.nextLine();
            char a[]=s.nextLine().toCharArray();
            char b[]=s.nextLine().toCharArray(); int z=0;
            for(int i=0;i<n-1;i++)
            {
                if(a[i]!=b[i] && b[i+1]!=a[i+1])
                { z+=1;  a[i]=b[i];  a[i+1]=b[i+1]; }
                else if(a[i]!=b[i])
                {z+=1;  a[i]=b[i];  }
            }

            if(a[n-1]!=b[n-1])
             z++;
            System.out.println(z);
      }
}


import java.util.*;
public class A
{
      public static void main(String ar[])
      {
            Scanner s=new Scanner(System.in);
            int n=s.nextInt();  s.nextLine();
            char a[]=s.nextLine().toCharArray();
            char b[]=s.nextLine().toCharArray(); int z=0;
            for(int i=0;i<n-1;i++)
            {
                if(a[i]!=b[i] && b[i+1]!=a[i+1] && a[i]!=b[i])
                { z+=1;  a[i]=b[i];  a[i+1]=b[i+1]; }
                else if(a[i]!=b[i])
                {z+=1;  a[i]=b[i];  }
            }

            if(a[n-1]!=b[n-1])
             z++;
            System.out.println(z);
      }
}


import java.util.*;
public class A
{
      public static void main(String ar[])
      {
            Scanner s=new Scanner(System.in);
            int n=s.nextInt();  s.nextLine();
            char a[]=s.nextLine().toCharArray();
            char b[]=s.nextLine().toCharArray(); int z=0;
            for(int i=0;i<n-1;i++)
            {
                if(a[i]!=b[i] && b[i+1]!=a[i+1] && a[i]!=a[i+1])
                { z+=1;  a[i]=b[i];  a[i+1]=b[i+1]; }
                else if(a[i]!=b[i])
                {z+=1;  a[i]=b[i];  }
            }

            if(a[n-1]!=b[n-1])
             z++;
            System.out.println(z);
      }
}


import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int n=Integer.parseInt(br.readLine());
            char c1[]=br.readLine().toCharArray();
            char c2[]=br.readLine().toCharArray();
            int a[]=new int[n];
            int b[]=new int[n];
            int S=0;
            for(int i=0;i<n;i++)
            { a[i]=c1[i]-48;  b[i]=c2[i]-48;  }

            for(int i=0;i<n-1;i++)
            {
                  if(a[i]!=b[i] && a[i+1]!=b[i+1] && a[i]!=a[i+1])
                  { S++;  a[i]=b[i];  a[i+1]=b[i+1]; }
                  else if(a[i]!=b[i])
                  { S++; a[i]=b[i]; }
            }
            if(a[n-1]!=b[n-1])
            { S++; a[n-1]=b[n-1]; }
            System.out.println(S);
      }
}


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

public class Contest {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		String s1 = br.readLine();
		String s2 = br.readLine();
		int c = 0;
		for (int i=0; i<n; i++) {
			if (i!=n-1&&s1.charAt(i)!=s2.charAt(i)&&s1.charAt(i+1)!=s2.charAt(i+1)&&s1.charAt(i)!=s1.charAt(i+1)) {
				c++;
				i++;
			}else if (s1.charAt(i)!=s2.charAt(i))c++;
		}
		System.out.println(c);
	}
}


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

public class Contest {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		String s1 = br.readLine();
		String s2 = br.readLine();
		int c = 0;
		for (int i=0; i<n; i++) {
			if (i!=n-1&&s1.charAt(i)!=s2.charAt(i)&&s1.charAt(i+1)!=s2.charAt(i+1)) {
				c++;
				i++;
			}else if (s1.charAt(i)!=s2.charAt(i))c++;
		}
		System.out.println(c);
	}
}


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

public class Contest {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		String s1 = br.readLine();
		String s2 = br.readLine();
		int c = 0;
		for (int i=0; i<n; i++) {
			if (i!=n-1&&s1.charAt(i)!=s2.charAt(i)&&s1.charAt(i+1)!=s2.charAt(i+1)) {
				c++;
				i++;
			}else c++;
		}
		System.out.println(c);
	}
}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

public class cde {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        String s1 = br.readLine();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '0' && s1.charAt(i) == '1')
                r[i] = 1;
            else if (s.charAt(i) == '1' && s1.charAt(i) == '0')
                r[i] = -1;

        }
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (r[i] + r[i + 1] == 0 && r[i] != 0 && r[i + 1] != 0) {
                r[i] = 0;
                r[i + 1] = 0;
                ans += 1;
                i += 2;
            } else i += 1;

        }

        for (int i = 0; i < n; i++)
            ans += Math.abs(r[i]);

        System.out.println(ans);

    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

public class cde {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        String s1 = br.readLine();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '0' && s1.charAt(i) == '1')
                r[i] = 1;
            else if (s.charAt(i) == '1' && s1.charAt(i) == '0')
                r[i] = -1;

        }
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (r[i] + r[i + 1] == 0 && r[i] != 0 && r[i + 1] != 0) {
                r[i] = 0;
                r[i + 1] = 0;
                ans += 1;
                i += 2;
            } else i += 1;

        }

        for (int i = 0; i < n; i++)
            ans += Math.abs(r[i]);

    }
}


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

public class cde {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        String s1 = br.readLine();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '0' && s1.charAt(i) == '1')
                r[i] = 1;
            else if (s.charAt(i) == '1' && s1.charAt(i) == '0')
                r[i] = -1;

        }
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (r[i] + r[i + 1] == 0 && r[i] != 0 && r[i + 1] != 0) {
                r[i] = 0;
                r[i + 1] = 0;
                ans += 1;
                i += 2;
            } else i += 1;

        }

        for (int i = 0; i < n; i++)
            ans += Math.abs(r[i]);

        System.out.println(ans);
    }
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        String s1 = br.readLine();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '0' && s1.charAt(i) == '1')
                r[i] = 1;
            else if (s.charAt(i) == '1' && s1.charAt(i) == '0')
                r[i] = -1;

        }
       // System.out.println(Arrays.toString(r));
        int ans = 0;
        for (int i = 0; i < n - 1;) {
            if (r[i] + r[i + 1] == 0 && r[i] != 0 && r[i + 1] != 0) {
                r[i] = 0;
                r[i + 1] = 0;
                ans += 1;
                i += 2;
            }
            else i+=1 ;

        }

        for (int i = 0; i < n; i++)
            ans += Math.abs(r[i]);

        System.out.println(ans);
    }
}


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

public class cde {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        String s1 = br.readLine();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '0' && s1.charAt(i) == '1')
                r[i] = 1;
            else if (s.charAt(i) == '1' && s1.charAt(i) == '0')
                r[i] = -1;

        }
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (r[i] + r[i + 1] == 0 && r[i] != 0 && r[i + 1] != 0) {
                r[i] = 0;
                r[i + 1] = 0;
                ans += 1;
                i += 2;
            }

        }

        for (int i = 0; i < n; i++)
            ans += Math.abs(r[i]);

        System.out.println(ans);
    }
}


import java.util.*;
public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        sc.nextLine();
        char[] ch1 = sc.nextLine().toCharArray();
        char[] ch2 = sc.nextLine().toCharArray();
        long cost=0;
        for(int i=0;i<n-1;i++)
        {
            if(ch1[i]==ch2[i+1]&&ch2[i]==ch1[i+1])
            {
                ch1[i] = ch1[i+1];
                ch1[i+1] = ch2[i];
                cost++;
                i++;
            }
            else if(ch1[i]==ch2[i])
            {
                continue;
            }
            else
            {
                cost++;
            }
        }
        if(ch1[n-1] != ch2[n-1]){
            cost++;
        }
        System.out.println(cost);
    }
}


import java.util.*;
public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        sc.nextLine();
        char[] ch1 = sc.nextLine().toCharArray();
        char[] ch2 = sc.nextLine().toCharArray();
        long cost=0;
        boolean flag = false;
        for(int i=0;i<n-1;i++)
        {
            if(ch1[i]==ch2[i+1]&&ch2[i]==ch1[i+1]&&ch1[i]!=ch2[i])
            {
                if(i==n-2)
                    flag = true;
                i++;
                cost++;
            }
            else if(ch1[i]==ch2[i])
            {
                continue;
            }
            else
            {
                cost++;
            }
            System.out.println(cost);
        }
        if(ch1[n-1] != ch2[n-1]&&!flag){
            cost++;
        }
        System.out.println(cost);
    }
}


import java.util.*;
public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        sc.nextLine();
        char[] ch1 = sc.nextLine().toCharArray();
        char[] ch2 = sc.nextLine().toCharArray();
        long cost=0;
        boolean flag = false;
        for(int i=0;i<n-1;i++)
        {
            if(ch1[i]==ch2[i+1]&&ch2[i]==ch1[i+1])
            {
                if(i==n-2)
                    flag = true;
                i++;
                cost++;
            }
            else if(ch1[i]==ch2[i])
            {
                continue;
            }
            else
            {
                cost++;
            }
            // System.out.println(cost);
        }
        if(ch1[n-1] != ch2[n-1]&&!flag){
            cost++;
        }
        System.out.println(cost);
    }
}


import java.util.*;
public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        sc.nextLine();
        char[] ch1 = sc.nextLine().toCharArray();
        char[] ch2 = sc.nextLine().toCharArray();
        long cost=0;
        boolean flag = false;
        for(int i=0;i<n-1;i++)
        {
            if(ch1[i]==ch2[i+1]&&ch2[i]==ch1[i+1]&&ch1[i]!=ch2[i])
            {
                if(i==n-2)
                    flag = true;
                i++;
                cost++;
            }
            else if(ch1[i]==ch2[i])
            {
                continue;
            }
            else
            {
                cost++;
            }
            //System.out.println(cost);
        }
        if(ch1[n-1] != ch2[n-1]&&!flag){
            cost++;
        }
        System.out.println(cost);
    }
}


import java.util.*;

public class Equalize {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        char[] a = sc.nextLine().toCharArray();
        char[] b = sc.nextLine().toCharArray();

        int i = 0, j = 0, sum = 0;
        while (i < a.length && j < b.length) {
            if (i + 1 < a.length && j + 1 < b.length && a[i] == b[j + 1] && b[j] == a[i + 1]) {
                char temp = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp;
                sum += 1;
                i++;
                j++;
            } else if (a[i] != b[j]) {
                i++;
                j++;
                sum += 1;
            } else  {
                i++;
                j++;
            }
        }
        System.out.println(sum);
    }
}


import java.util.*;

public class Equalize {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        char[] a = sc.nextLine().toCharArray();
        char[] b = sc.nextLine().toCharArray();

        int i = 0, j = 0, sum = 0;
        while (i < a.length && j < b.length) {
            if (i + 1 < a.length && j + 1 < b.length && b[j] == a[i + 1] && a[i + 1] != b[j + 1] && a[i] == b[j + 1]) {
                char temp = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp;
                sum += 1;
                i++;
                j++;
            } else if (a[i] != b[j]) {
                i++;
                j++;
                sum += 1;
            } else  {
                i++;
                j++;
            }
        }
        System.out.println(sum);
    }
}


import java.util.*;

public class Equalize {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        char[] a = sc.nextLine().toCharArray();
        char[] b = sc.nextLine().toCharArray();

        int i = 0, j = 0, sum = 0;
        while (i < a.length && j < b.length) {
            if (i + 1 < a.length && j + 1 < b.length && b[j] == a[i + 1] && a[i + 1] != b[j + 1]) {
                char temp = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp;
                sum += 1;
                i++;
                j++;
            } else if (a[i] != b[j]) {
                i++;
                j++;
                sum += 1;
            } else  {
                i++;
                j++;
            }
        }
        System.out.println(sum);
    }
}


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

public class Main implements Runnable {

    int maxn = (int)2e5+111;
    long mod = (long)1e9+7;
    int n,m,k;

    void solve() throws Exception {
        n = in.nextInt();
        char a[] = in.nextToken().toCharArray();
        char b[] = in.nextToken().toCharArray();

        int cnt = 0;
        for (int i=0; i<n-1; i++) {
            if (a[i]==b[i]) continue;
            if (a[i]==b[i+1] && a[i+1]==b[i]) {
                char t = a[i];
                a[i] = a[i+1];
                a[i+1] = t;
            }
            cnt++;
        }

        if (a[n-1]!=b[n-1]) cnt++;

        out.println(cnt);
    }

    String fileInName = "";

    boolean file = false;
    boolean isAcmp = false;

    static Throwable throwable;
    public static void main (String [] args) throws Throwable {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        thread.run();
        if (throwable != null)
            throw throwable;
    }

    FastReader in;
    PrintWriter out;

    public void run() {
        String fileIn = "absum.in";
        String fileOut = "absum.out";

        try {
            if (isAcmp) {
                if (file) {
                    in = new FastReader(new BufferedReader(new FileReader(fileIn)));
                    out = new PrintWriter (fileOut);
                } else {
                    in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
                    out = new PrintWriter(System.out);
                }
            } else if (file) {
                in = new FastReader(new BufferedReader(new FileReader(fileInName+".in")));
                out = new PrintWriter (fileInName + ".out");
            } else {
                in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(System.out);
            }

            solve();
        } catch(Exception e) {
            throwable = e;
        } finally {
            out.close();
        }

    }

}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        if (!tk.hasMoreTokens()) return nextToken();
        else
            return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


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

public class Main implements Runnable {

    int maxn = (int)2e5+111;
    long mod = (long)1e9+7;
    int n,m,k;

    void solve() throws Exception {
        n = in.nextInt();
        char a[] = in.nextToken().toCharArray();
        char b[] = in.nextToken().toCharArray();

        int cnt = 0;
        for (int i=0; i<n-1; i++) {
            if (a[i]==b[i]) continue;
            if (a[i+1]==b[i]) {
                char temp = a[i];
                a[i] = a[i+1];
                a[i+1] = temp;
                cnt++;
            } else {
                cnt++;
            }
        }

        if (a[n-1]!=b[n-1]) cnt++;

        out.println(cnt);
    }

    String fileInName = "";

    boolean file = false;
    boolean isAcmp = false;

    static Throwable throwable;
    public static void main (String [] args) throws Throwable {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        thread.run();
        if (throwable != null)
            throw throwable;
    }

    FastReader in;
    PrintWriter out;

    public void run() {
        String fileIn = "absum.in";
        String fileOut = "absum.out";

        try {
            if (isAcmp) {
                if (file) {
                    in = new FastReader(new BufferedReader(new FileReader(fileIn)));
                    out = new PrintWriter (fileOut);
                } else {
                    in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
                    out = new PrintWriter(System.out);
                }
            } else if (file) {
                in = new FastReader(new BufferedReader(new FileReader(fileInName+".in")));
                out = new PrintWriter (fileInName + ".out");
            } else {
                in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(System.out);
            }

            solve();
        } catch(Exception e) {
            throwable = e;
        } finally {
            out.close();
        }

    }

}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        if (!tk.hasMoreTokens()) return nextToken();
        else
            return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


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

public class Main implements Runnable {

    int maxn = (int)2e5+111;
    long mod = (long)1e9+7;
    int n,m,k;

    void solve() throws Exception {
        n = in.nextInt();
        char a[] = in.nextToken().toCharArray();
        char b[] = in.nextToken().toCharArray();

        int cnt = 0;
        for (int i=0; i<n-1; i++) {
            if (a[i]==b[i]) continue;
            if (a[i+1]==b[i]) {
                a[i+1] = a[i];
                a[i] = b[i];
                cnt++;
            } else {
                cnt++;
            }
        }

        if (a[n-1]!=b[n-1]) cnt++;

        out.println(cnt);
    }

    String fileInName = "";

    boolean file = false;
    boolean isAcmp = false;

    static Throwable throwable;
    public static void main (String [] args) throws Throwable {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        thread.run();
        if (throwable != null)
            throw throwable;
    }

    FastReader in;
    PrintWriter out;

    public void run() {
        String fileIn = "absum.in";
        String fileOut = "absum.out";

        try {
            if (isAcmp) {
                if (file) {
                    in = new FastReader(new BufferedReader(new FileReader(fileIn)));
                    out = new PrintWriter (fileOut);
                } else {
                    in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
                    out = new PrintWriter(System.out);
                }
            } else if (file) {
                in = new FastReader(new BufferedReader(new FileReader(fileInName+".in")));
                out = new PrintWriter (fileInName + ".out");
            } else {
                in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(System.out);
            }

            solve();
        } catch(Exception e) {
            throwable = e;
        } finally {
            out.close();
        }

    }

}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        if (!tk.hasMoreTokens()) return nextToken();
        else
            return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.

*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
        */
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        char[] a = br.readLine().toCharArray();
        char[] b = br.readLine().toCharArray();

        int prevIndex = -1;
        int count=0;
        for(int i=0;i<n;i++){
            if(a[i]!= b[i] && a[i+1]!=a[i]){
                count++;
                i++;
            }
        }
        System.out.println(count);
    }
}


/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.

*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
        */
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        char[] a = br.readLine().toCharArray();
        char[] b = br.readLine().toCharArray();

        int prevIndex = -1;
        int count=0;
        for(int i=0;i<n;i++){
            if(a[i]!= b[i]){
                count++;
                if( i+1<n && a[i+1]!=a[i])  i++;
            }
        }
        System.out.println(count);
    }
}


/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.

*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
        */
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        char[] a = br.readLine().toCharArray();
        char[] b = br.readLine().toCharArray();

        int prevIndex = -1;
        int count=0;
        for(int i=0;i<n;i++){
            if(a[i]!= b[i]){
                count++;
                i++;
            }
        }
        System.out.println(count);
    }
}


/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.

*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
        */
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        char[] a = br.readLine().toCharArray();
        char[] b = br.readLine().toCharArray();

        int prevIndex = -1;
        int count=0;
        for(int i=0;i<n;i++){
            if(a[i]!= b[i] && i+1<n && a[i+1]!=a[i]){
                count++;
                i++;
            }
        }
        System.out.println(count);
    }
}


import java.util.Scanner;

public class Equalize {

	public static void main(String[] args) {

		Scanner sc = new Scanner (System.in) ;

		int length = Integer.parseInt(sc.nextLine()) ;

		String s1 = sc.nextLine() ;
		String s2 = sc.nextLine() ;
		int count = 0 ;

		for(int i = 0 ; i < length ; i++)
		{
			if(s1.charAt(i) != s2.charAt(i))
			{
				boolean changed = false ;
				for(int j = i + 2 ; j > i && j < length ; j --)
				{
					if(s1.charAt(j) != s2.charAt(j))
					{
						if(j - i == 1 || j - i == 2)
						{
							String s = "" ;
							for(int k = 0 ; k < length ; k++)
							{
								if(k == i)
									s += s2.charAt(i) ;
								else
									if(k == j)
										s += s2.charAt(j) ;
									else
										s += s1.charAt(k) ;
							}
							s1 = s ;
							count += j - i ;
							changed = true ;
						}
					}
				}
				if(!changed)
					count += 1 ;
			}

		}

		System.out.println(count) ;

	}

}