#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    while(q--){
        int n;
        cin >> n;
        int one = 0, zero = 0, odd = 0, even = 0 ,ans = n ;
        for(int i=0;i<n;i++)
        {
            string s,re;
            cin >> s;
            for(int j=0;j<s.size();j++){
                if(s[j] == '1')
                    one++;
                else
                    zero++;
            }
            int si = s.size();
            if(si&1 )
                odd++;
        }

        //cout<<"sss : ";

        //cout<<"one = "<<one<<" , zero = "<<zero<<endl;
        ans--;
        if( (odd&1 && ((one&1)^(zero&1)) ) || ( !(odd&1) && !(one&1) && !(zero&1) ) )
            ans++;

        cout<<ans<<endl;

    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    while(q--){
        int n;
        cin >> n;
        int one = 0, zero = 0, odd = 0, even = 0 ,ans = n ;
        for(int i=0;i<n;i++)
        {
            string s;
            cin >> s;
            for(int j=0;j<s.size();j++){
                if(s[j] == '1')
                    one++;
                else
                    zero++;
            }
            int si = s.size();
            if(si&1 )
                odd++;
        }

        ///cout<<"sss";
        if( (odd&1 && one&1 && zero&1) || ( !(odd&1) && ((one&1)||(zero&1) ) ) )
            ans--;

        cout<<ans<<endl;

    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    while(q--){
        int n;
        cin >> n;
        int one = 0, zero = 0, odd = 0, even = 0 ,ans = n ;
        for(int i=0;i<n;i++)
        {
            string s,re;
            cin >> s;
            for(int j=0;j<s.size();j++){
                if(s[j] == '1')
                    one++;
                else
                    zero++;
            }
            int si = s.size();
            if(si&1 )
                odd++;
        }

        //cout<<"sss : ";

        //cout<<"one = "<<one<<" , zero = "<<zero<<endl;
        ans--;
        if( (odd&1 && ((one&1)^(zero&1)) ) || ( !(odd&1) && ((!(one&1) && !(zero&1))||( odd>1 &&  one&1 && zero&1) ) ) )
            ans++;

        cout<<ans<<endl;

    }

}


#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		int one=0,zero=0;
		int streven=0,strodd=0;
		std::vector<string> v;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v.push_back(s);
			for(int j=0;j<s.length();j++){
				if(s[j]=='1') one+=1;
				else zero+=1;
			}
			if(s.length()%2==0)streven+=1;
			else strodd+=1;
		}
		if(strodd==0){
			if(one%2==0 && zero%2==0){
				cout<<n<<"\n";
			}
			else if(one%2==1 && zero%2==1){
				cout<<n-1<<"\n";
			}
		}
		else if(strodd==1){
			cout<<n<<"\n";
		}
		else{
			if(strodd%2==0){
				cout<<n-1<<"\n";
			}
			else cout<<n<<"\n";
		}
		// if(one%2==0 && zero%2==0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2==0 && zero%2!=0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2!=0 && zero%2==0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2!=0 && zero%2!=0){
		// 	if(streven%2==0 && strodd%2==0){
		// 		cout<<n-1<<"\n";
		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){
		// 		cout<<n<<"\n";
		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){
		// 		cout<<n-1<<"\n";
		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){
		// 		cout<<n<<"\n";
		// 	}
		// }
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		int one=0,zero=0;
		int streven=0,strodd=0;
		std::vector<string> v;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v.push_back(s);
			for(int j=0;j<s.length();j++){
				if(s[i]=='1') one+=1;
				else zero+=1;
			}
			if(s.length()%2==0)streven+=1;
			else strodd+=1;
		}
		if(strodd==0){
			if(one%2==0 && zero%2==0){
				cout<<n<<"\n";
			}
			else if(one%2==1 && zero%2==1){
				cout<<n-1<<"\n";
			}
		}
		else if(strodd==1){
			cout<<n<<"\n";
		}
		else{
			if(strodd%2==0){
				cout<<n-1<<"\n";
			}
			else cout<<n<<"\n";
		}
		// if(one%2==0 && zero%2==0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2==0 && zero%2!=0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2!=0 && zero%2==0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2!=0 && zero%2!=0){
		// 	if(streven%2==0 && strodd%2==0){
		// 		cout<<n-1<<"\n";
		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){
		// 		cout<<n<<"\n";
		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){
		// 		cout<<n-1<<"\n";
		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){
		// 		cout<<n<<"\n";
		// 	}
		// }
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		int one=0,zero=0;
		int streven=0,strodd=0;
		std::vector<string> v;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v.push_back(s);
			for(int j=0;j<s.length();j++){
				if(s[i]=='1') one+=1;
				else zero+=1;
			}
			if(s.length()%2==0)streven+=1;
			else strodd+=1;
		}
		if(strodd==0){
			if(one%2==0 && zero%2==0){
				cout<<n-1<<"\n";
			}
			else if(one%2==1 && zero%2==1){
				cout<<n<<"\n";
			}
		}
		else if(strodd==1){
			cout<<n<<"\n";
		}
		else{
			if(strodd%2==0){
				cout<<n-1<<"\n";
			}
			else cout<<n<<"\n";
		}
		// if(one%2==0 && zero%2==0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2==0 && zero%2!=0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2!=0 && zero%2==0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2!=0 && zero%2!=0){
		// 	if(streven%2==0 && strodd%2==0){
		// 		cout<<n-1<<"\n";
		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){
		// 		cout<<n<<"\n";
		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){
		// 		cout<<n-1<<"\n";
		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){
		// 		cout<<n<<"\n";
		// 	}
		// }
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		int one=0,zero=0;
		int streven=0,strodd=0;
		std::vector<string> v;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v.push_back(s);
			for(int j=0;j<s.length();j++){
				if(s[j]=='1') one+=1;
				else zero+=1;
			}
			if(s.length()%2==0)streven+=1;
			else strodd+=1;
		}
		if(strodd==0){
			if(one%2==0 && zero%2==0){
				cout<<n<<"\n";
			}
			else if(one%2==1 && zero%2==1){
				cout<<n-1<<"\n";
			}
		}
		else if(strodd==1){
			cout<<n<<"\n";
		}
		else{
			if(strodd%2==0){
				cout<<n<<"\n";
			}
			else{
				cout<<n<<"\n";
			}
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		int one=0,zero=0;
		int streven=0,strodd=0;
		std::vector<string> v;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v.push_back(s);
			for(int j=0;j<s.length();j++){
				if(s[j]=='1') one+=1;
				else zero+=1;
			}
			if(s.length()%2==0)streven+=1;
			else strodd+=1;
		}
		if(strodd==0){
			if(one%2==0 && zero%2==0){
				cout<<n<<"\n";
			}
			else if(one%2==1 && zero%2==1){
				cout<<n-1<<"\n";
			}
		}
		else if(strodd==1){
			cout<<n<<"\n";
		}
		else{
			if(strodd%2==0){
				cout<<n<<"\n";
			}
			else cout<<n-1<<"\n";
		}
		// if(one%2==0 && zero%2==0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2==0 && zero%2!=0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2!=0 && zero%2==0){
		// 	if(streven%2==0 && strodd%2==0){

		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){

		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){

		// 	}
		// }
		// else if(one%2!=0 && zero%2!=0){
		// 	if(streven%2==0 && strodd%2==0){
		// 		cout<<n-1<<"\n";
		// 	}
		// 	else if(streven%2==0 && strodd%2!=0){
		// 		cout<<n<<"\n";
		// 	}
		// 	else if(streven%2!=0 && strodd%2==0){
		// 		cout<<n-1<<"\n";
		// 	}
		// 	else if(streven%2!=0 && strodd%2!=0){
		// 		cout<<n<<"\n";
		// 	}
		// }
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		int one=0,zero=0;
		int streven=0,strodd=0;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			for(int j=0;j<s.length();j++){
				if(s[j]=='1') one+=1;
				else zero+=1;
			}
			if(s.length()%2==0) streven+=1;
			else strodd+=1;
		}
		if(strodd==0){
			if(one%2==0 && zero%2==0)
				cout<<n<<"\n";
			else if(one%2==1 && zero%2==1)
				cout<<n-1<<"\n";
		}
		else cout<<n<<"\n";
	}
}


#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld double
#define  pb push_back
#define  ff(n) for(i=0; i<n; i++)
#define mo 1000000007
ll max(ll a,ll b){return (a>b)?a:b;}
ll min(ll a,ll b){return (a<b)?a:b;}
ll gcd(ll a,ll b)
    {
        while(1)
        {
            if(a==0)
             return b;
            b%=a;
            if(b==0)
             return a;
            a%=b;

        }
    }
ll p2(ll k,ll n)
    {
        ll re=1;
        while(n)
        {
            if(n%2==1)
             re=(re*k);
            k*=k;
            n/=2;
        }
     return re;
    }
int main(){
    ll n,m,i,j,t,k;
    cin>>t;
    for(ll ii=0;ii<t;ii++)
    {
        cin>>n;
        vector<string>a(n);
        for(i=0;i<n;i++)
         cin>>a[i];
       // cout<<i<<endl;
        ll s=0,p=0,q=0;
        for(i=0;i<n;i++)
         {
           //  cout<<i<<endl;
             k=0;
             for(j=0;j<a[i].size();j++)
              k+=a[i][j]-'0';
             if(a[i].size()%2==0)
             {
                 if(k%2==0)
                  q++;
                 else
                   s++;
             }
             else
              p++;
         }
        q+=p;
        if(p!=0)
          q=n;
         else
          q+=s-s%2;
         cout<<q<<endl;
    }
}


#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld double
#define  pb push_back
#define  ff(n) for(i=0; i<n; i++)
#define mo 1000000007
ll max(ll a,ll b){return (a>b)?a:b;}
ll min(ll a,ll b){return (a<b)?a:b;}
ll gcd(ll a,ll b)
    {
        while(1)
        {
            if(a==0)
             return b;
            b%=a;
            if(b==0)
             return a;
            a%=b;

        }
    }
ll p2(ll k,ll n)
    {
        ll re=1;
        while(n)
        {
            if(n%2==1)
             re=(re*k);
            k*=k;
            n/=2;
        }
     return re;
    }
int main(){
    ll n,m,i,j,t,k;
    cin>>t;
    for(ll ii=0;ii<t;ii++)
    {
        cin>>n;
        vector<string>a(n);

        for(i=0;i<n;i++)
         cin>>a[i];
        ll s=0,p=0;
        k=0;
        vector<ll>b;
        for(i=0;i<n;i++)
        {

            for(j=0;j<a[i].size();j++)
              k+=a[i][j]-'0';
            p+=a[i].size();
        }
       // cout<<k<<" "<<p<<endl;
        if(k%2==p%2 || (p-k)%2==p%2)
         cout<<n<<endl;
        else
         cout<<n-1<<endl;

    }
}


#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld double
#define  pb push_back
#define  ff(n) for(i=0; i<n; i++)
#define mo 1000000007
ll max(ll a,ll b){return (a>b)?a:b;}
ll min(ll a,ll b){return (a<b)?a:b;}
ll gcd(ll a,ll b)
    {
        while(1)
        {
            if(a==0)
             return b;
            b%=a;
            if(b==0)
             return a;
            a%=b;

        }
    }
ll p2(ll k,ll n)
    {
        ll re=1;
        while(n)
        {
            if(n%2==1)
             re=(re*k);
            k*=k;
            n/=2;
        }
     return re;
    }
int main(){
    ll n,m,i,j,t,k;
    cin>>t;
    for(ll ii=0;ii<t;ii++)
    {
        cin>>n;
        vector<string>a(n);

        for(i=0;i<n;i++)
         cin>>a[i];
        ll s=0,p=0;
        k=0;
        vector<ll>b;
        for(i=0;i<n;i++)
        {
            k=0;
            for(j=0;j<a[i].size();j++)
              k+=a[i][j]-'0';
            p+=a[i].size();
        }
        if(k%2==p%2 || (p-k)%2==p%2)
         cout<<n<<endl;
        else
         cout<<n-1<<endl;

    }
}


#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld double
#define  pb push_back
#define  ff(n) for(i=0; i<n; i++)
#define mo 1000000007
ll max(ll a,ll b){return (a>b)?a:b;}
ll min(ll a,ll b){return (a<b)?a:b;}
ll gcd(ll a,ll b)
    {
        while(1)
        {
            if(a==0)
             return b;
            b%=a;
            if(b==0)
             return a;
            a%=b;

        }
    }
ll p2(ll k,ll n)
    {
        ll re=1;
        while(n)
        {
            if(n%2==1)
             re=(re*k);
            k*=k;
            n/=2;
        }
     return re;
    }
int main(){
    ll n,m,i,j,t,k;
    cin>>t;
    for(ll ii=0;ii<t;ii++)
    {
        cin>>n;
        vector<string>a(n);

        for(i=0;i<n;i++)
         cin>>a[i];
        ll s=0,p=0;
        k=0;
        vector<ll>b;
        for(i=0;i<n;i++)
        {
            k=0;
            for(j=0;j<a[i].size();j++)
              k+=a[i][j]-'0';
            p+=a[i].size();
        }
        if(k%2==p%2)
         cout<<n<<endl;
        else
         cout<<n-1<<endl;

    }
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=3e5+5;

char s[maxn];

char ans[maxn];

//int num[maxn];

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		int n1=0,n2=0;
		int l1=0,l2=0;
		for(int i=0;i<n;i++){
			scanf("%s",s);
			int len=strlen(s);
			for(int i=0;i<len;i++){
				if(s[i]=='0') n2++;
				else n1++;
			}
			if(len&1) l1++;
			else l2++;
		}
		int flg=0;
		if((n1+n2)%2==0&&((n1&1)==1||(n2&1==1))){
			if(l1==0||(l1&1)&1==1) flg=1;
		}
		printf("%d\n",n-flg);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=3e5+5;

char s[maxn];

char ans[maxn];

//int num[maxn];

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		int n1=0,n2=0;
		int l1=0,l2=0;
		for(int i=0;i<n;i++){
			scanf("%s",s);
			int len=strlen(s);
			for(int i=0;i<len;i++){
				if(s[i]=='0') n2++;
				else n1++;
			}
			if(len&1) l1++;
			else l2++;
		}
		int flg=0;
		if((n1+n2)%2!=0){
			if(l1&1==0) flg=1;
		}
		printf("%d\n",n-flg);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=3e5+5;

char s[maxn];

char ans[maxn];

//int num[maxn];

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		int n1=0,n2=0;
		int l1=0,l2=0;
		for(int i=0;i<n;i++){
			scanf("%s",s);
			int len=strlen(s);
			for(int i=0;i<len;i++){
				if(s[i]=='0') n2++;
				else n1++;
			}
			if(len&1) l1++;
			else l2++;
		}
		int flg=0;
		if((n1+n2)%2==0&&((n1&1)==1||(n2&1==1))){
			if((l1&1)==0) flg=1;
		}
		printf("%d\n",n-flg);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=1e3+5;

char s[maxn];

int num[maxn];

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		int n0=0,n1=0;
		for(int i=0;i<n;i++){
			scanf("%s",s);
			int len=strlen(s);
			for(int i=0;i<len;i++){
				if(s[i]=='0') n0++;
				else n1++;
			}
			num[i]=len;
		}
		sort(num,num+n);
		int ans=0;
		for(int i=0;i<n;i++){
			if(n1>=num[i]){
				n1-=num[i];ans++;
			}
			else if(n0>=num[i]){
				n0-=num[i];ans++;
			}
			else if(num[i]&1){
				for(int j=1;j<num[i];j+=2){
					if(n0>=j&&n1>=num[i]-j){
						n0-=j;n1-=num[i]-j;ans++;
						break;
					}
					if(n1>=j&&n0>=num[i]-j){
						n1-=j;n1-=num[i]-j;ans++;
						break;
					}
				}
			}
			else{
				for(int j=0;j<num[i];j+=2){
					if(n0>=j&&n1>=num[i]-j){
						n0-=j;n1-=num[i]-j;ans++;
						break;
					}
					if(n1>=j&&n0>=num[i]-j){
						n1-=j;n1-=num[i]-j;ans++;
						break;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=3e5+5;

char s[maxn];

char ans[maxn];

//int num[maxn];

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		int n1=0,n2=0;
		int l1=0,l2=0;
		for(int i=0;i<n;i++){
			scanf("%s",s);
			int len=strlen(s);
			for(int i=0;i<len;i++){
				if(s[i]=='0') n2++;
				else n1++;
			}
			if(len&1) l1++;
			else l2++;
		}
		int flg=0;
		if((n1+n2)%2==0){
//			printf("%d\n",n1+n2);
			if((l1&1)==0) flg=1;
		}
		printf("%d\n",n-flg);
	}
	return 0;
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;

public class MinimizeTheInteger {
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    long L_INF = (1L << 60L);

    void solve() {
        int n, m;
        char s[] = ns().toCharArray();
        n = s.length;
        Queue<Character> odd = new LinkedList<>();
        Queue<Character> eve = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            if(s[i]%2==0)
                eve.add(s[i]);
            else
                odd.add(s[i]);
        }
        StringBuilder ans = new StringBuilder();
        while(!(odd.isEmpty() && eve.isEmpty())){
            if(odd.isEmpty())
                ans.append(eve.poll());
            else if(eve.isEmpty())
                ans.append(odd.poll());
            if(odd.isEmpty() || eve.isEmpty())
                continue;
            if(eve.peek()<odd.peek())
                ans.append(eve.poll());
            else
                ans.append(odd.poll());
        }
        System.out.println(ans);
    }

    void run() throws Exception {
        //		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        is = System.in;
        pw = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        int t = ni();
        while (t-- > 0)
            solve();
        pw.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

    public static void main(String[] args) throws Exception {
        new MinimizeTheInteger().run();
    }

    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (!oj) System.out.println(Arrays.deepToString(o));
    }
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e8 + 7)
#define pi acos(-1)
using namespace std;

char ch[2105], ch2[2105], dp[2105][2], ans[2105][2];

int main()
{
    mem(dp, -1);
    scanf("%s%*c%s%*c", ch, ch2);
    int len = strlen(ch);
    int len2 = strlen(ch2);
    bool flag = 0;
    for(int i = 0;i < len2;i++)
    {
        int tmp = 0, pos2 = i, pos = 0;
        while(pos < len&&pos2 < len2)
        {
            if(ch2[pos2] == ch[pos])
                pos2++, pos++, flag = 1;
            else
            {
                flag = 0;
                if((dp[i][1] - dp[i][0] + 1 < pos - tmp)||(dp[i][1] - dp[i][0] + 1 <= pos - tmp&&dp[i][1] == -1))
                    dp[i][1] = pos - 1, dp[i][0] = tmp;
                while(pos < len)
                {
                    if(ch2[i] != ch[pos])
                        pos++;
                    else
                        break;
                }
                pos2 = i, tmp = pos;
            }
        }
        if(flag)
        {
            if((dp[i][1] - dp[i][0] + 1 < pos - tmp)||(dp[i][1] - dp[i][0] + 1 <= pos - tmp&&dp[i][1] == -1))
                dp[i][1] = pos - 1, dp[i][0] = tmp;
        }
    }
    flag = 0;
    for(int i = 0;i < len2;i++)
    {
        int tmp = len - 1, pos2 = i, pos = len - 1;
        while(pos >= 0&&pos2 < len2)
        {
            if(ch2[pos2] == ch[pos])
                pos2++, pos--, flag = 1;
            else
            {
                flag = 0;
                if((abs(dp[i][1] - dp[i][0]) + 1 < tmp - pos)||((abs(dp[i][1] - dp[i][0]) + 1 <= tmp - pos&&dp[i][1] == -1)))
                    dp[i][1] = pos + 1, dp[i][0] = tmp;
                while(pos >= 0)
                {
                    if(ch2[i] != ch[pos])
                        pos--;
                    else
                        break;
                }
                pos2 = i, tmp = pos;
            }
        }
        if(flag)
        {
            if((abs(dp[i][1] - dp[i][0]) + 1 < tmp - pos)||((abs(dp[i][1] - dp[i][0]) + 1 <= tmp - pos&&dp[i][1] == -1)))
                dp[i][1] = pos + 1, dp[i][0] = tmp;
        }
    }
    int nn = 0;
    flag = 0;
    for(int i = 0;i < len2;i++)
    {
        ans[nn][0] = dp[i][0];
        ans[nn++][1] = dp[i][1];
        if(dp[i][0] == -1||dp[i][1] == -1)
        {
            flag = 1;
            break;
        }
        i = i + abs(dp[i][0] - dp[i][1]);
    }
    if(flag)
    {
        printf("-1\n");
        return 0;
    }
    printf("%d\n", nn);
    for(int i = 0;i < nn;i++)
        printf("%d %d\n", ans[i][0] + 1, ans[i][1] + 1);
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e8 + 7)
#define pi acos(-1)
using namespace std;

char ch[2105], ch2[2105];
int dp[2105][2], ans[2105][2];

int main()
{
    mem(dp, -1);
    scanf("%s%*c%s%*c", ch, ch2);
    int len = strlen(ch);
    int len2 = strlen(ch2);
    bool flag;
    for(int i = 0;i < len2;i++)
    {
        flag = 0;
        int tmp = 0, pos2 = i, pos = 0;
        while(pos < len&&pos2 < len2)
        {
            if(ch2[pos2] == ch[pos])
                pos2++, pos++, flag = 1;
            else
            {
                flag = 0;
                if((dp[i][1] - dp[i][0] + 1 < pos - tmp)||(dp[i][1] - dp[i][0] + 1 <= pos - tmp&&dp[i][1] == -1))
                    dp[i][1] = pos - 1, dp[i][0] = tmp;
                while(pos < len)
                {
                    if(ch2[i] != ch[pos])
                        pos++;
                    else
                        break;
                }
                if(pos == len)
                    break;
                pos2 = i, tmp = pos;
            }
        }
        if(flag)
        {
            if((dp[i][1] - dp[i][0] + 1 < pos - tmp)||(dp[i][1] - dp[i][0] + 1 <= pos - tmp&&dp[i][1] == -1))
                dp[i][1] = pos - 1, dp[i][0] = tmp;
        }
        i += dp[i][1] - dp[i][0];
    }
    for(int i = 0;i < len2;i++)
    {
        flag = 0;
        int tmp = len - 1, pos2 = i, pos = len - 1;
        while(pos >= 0&&pos2 < len2)
        {
            if(ch2[pos2] == ch[pos])
                pos2++, pos--, flag = 1;
            else
            {
                flag = 0;
                if((abs(dp[i][1] - dp[i][0]) + 1 < tmp - pos)||((abs(dp[i][1] - dp[i][0]) + 1 <= tmp - pos&&dp[i][1] == -1)))
                    dp[i][1] = pos + 1, dp[i][0] = tmp;
                while(pos >= 0)
                {
                    if(ch2[i] != ch[pos])
                        pos--;
                    else
                        break;
                }
                if(pos == -1)
                    break;
                pos2 = i, tmp = pos;
            }
        }
        if(flag)
        {
            if((abs(dp[i][1] - dp[i][0]) + 1 < tmp - pos)||((abs(dp[i][1] - dp[i][0]) + 1 <= tmp - pos&&dp[i][1] == -1)))
                dp[i][1] = pos + 1, dp[i][0] = tmp;
        }
        i += abs(dp[i][1] - dp[i][0]);
    }
    int nn = 0;
    flag = 0;
    for(int i = 0;i < len2;i++)
    {
        ans[nn][0] = dp[i][0];
        ans[nn++][1] = dp[i][1];
        if(dp[i][0] == -1||dp[i][1] == -1)
        {
            flag = 1;
            break;
        }
        i = i + abs(dp[i][0] - dp[i][1]);
    }
    if(flag)
    {
        printf("-1\n");
        return 0;
    }
    printf("%d\n", nn);
    for(int i = 0;i < nn;i++)
        printf("%d %d\n", ans[i][0] + 1, ans[i][1] + 1);
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e8 + 7)
#define pi acos(-1)
using namespace std;

char ch[2105], ch2[2105];
int dp[2105][2], ans[2105][2];

int main()
{
    mem(dp, -1);
    scanf("%s%*c%s%*c", ch, ch2);
    int len = strlen(ch);
    int len2 = strlen(ch2);
    bool flag;
    for(int i = 0;i < len2;i++)
    {
        flag = 0;
        int tmp = 0, pos2 = i, pos = 0;
        while(pos < len&&pos2 < len2)
        {
            if(ch2[pos2] == ch[pos])
                pos2++, pos++, flag = 1;
            else
            {
                flag = 0;
                if((dp[i][1] - dp[i][0] + 1 < pos - tmp)||(dp[i][1] - dp[i][0] + 1 <= pos - tmp&&dp[i][1] == -1))
                    dp[i][1] = pos - 1, dp[i][0] = tmp;
                while(pos < len)
                {
                    if(ch2[i] != ch[pos])
                        pos++;
                    else
                        break;
                }
                if(pos == len)
                    break;
                pos2 = i, tmp = pos;
            }
        }
        if(flag)
        {
            if((dp[i][1] - dp[i][0] + 1 < pos - tmp)||(dp[i][1] - dp[i][0] + 1 <= pos - tmp&&dp[i][1] == -1))
                dp[i][1] = pos - 1, dp[i][0] = tmp;
        }
    }
    for(int i = 0;i < len2;i++)
    {
        flag = 0;
        int tmp = len - 1, pos2 = i, pos = len - 1;
        while(pos >= 0&&pos2 < len2)
        {
            if(ch2[pos2] == ch[pos])
                pos2++, pos--, flag = 1;
            else
            {
                flag = 0;
                if((abs(dp[i][1] - dp[i][0]) + 1 < tmp - pos)||((abs(dp[i][1] - dp[i][0]) + 1 <= tmp - pos&&dp[i][1] == -1)))
                    dp[i][1] = pos + 1, dp[i][0] = tmp;
                while(pos >= 0)
                {
                    if(ch2[i] != ch[pos])
                        pos--;
                    else
                        break;
                }
                if(pos == -1)
                    break;
                pos2 = i, tmp = pos;
            }
        }
        if(flag)
        {
            if((abs(dp[i][1] - dp[i][0]) + 1 < tmp - pos)||((abs(dp[i][1] - dp[i][0]) + 1 <= tmp - pos&&dp[i][1] == -1)))
                dp[i][1] = pos + 1, dp[i][0] = tmp;
        }
    }
    int nn = 0;
    flag = 0;
    for(int i = 0;i < len2;i++)
    {
        ans[nn][0] = dp[i][0];
        ans[nn++][1] = dp[i][1];
        if(dp[i][0] == -1||dp[i][1] == -1)
        {
            flag = 1;
            break;
        }
        i = i + abs(dp[i][0] - dp[i][1]);
    }
    if(flag)
    {
        printf("-1\n");
        return 0;
    }
    printf("%d\n", nn);
    for(int i = 0;i < nn;i++)
        printf("%d %d\n", ans[i][0] + 1, ans[i][1] + 1);
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e8 + 7)
#define pi acos(-1)
using namespace std;

char ch[2105], ch2[2105];
int dp[2105][2], ans[2105][2];

int main()
{
    mem(dp, -1);
    scanf("%s%*c%s%*c", ch, ch2);
    int len = strlen(ch);
    int len2 = strlen(ch2);
    bool flag;
    for(int i = 0;i < len2;i++)
    {
        flag = 0;
        int tmp = 0, pos2 = i, pos = 0;
        while(pos < len&&pos2 < len2)
        {
            if(ch2[pos2] == ch[pos])
                pos2++, pos++, flag = 1;
            else
            {
                flag = 0;
                if((dp[i][1] - dp[i][0] + 1 < pos - tmp)||(dp[i][1] - dp[i][0] + 1 <= pos - tmp&&dp[i][1] == -1))
                    dp[i][1] = pos - 1, dp[i][0] = tmp;
                pos = tmp + 1;
                while(pos < len)
                {
                    if(ch2[i] != ch[pos])
                        pos++;
                    else
                        break;
                }
                if(pos == len)
                    break;
                pos2 = i, tmp = pos;
            }
        }
        if(flag)
        {
            if((dp[i][1] - dp[i][0] + 1 < pos - tmp)||(dp[i][1] - dp[i][0] + 1 <= pos - tmp&&dp[i][1] == -1))
                dp[i][1] = pos - 1, dp[i][0] = tmp;
        }
    }
    for(int i = 0;i < len2;i++)
    {
        flag = 0;
        int tmp = len - 1, pos2 = i, pos = len - 1;
        while(pos >= 0&&pos2 < len2)
        {
            if(ch2[pos2] == ch[pos])
                pos2++, pos--, flag = 1;
            else
            {
                flag = 0;
                if((abs(dp[i][1] - dp[i][0]) + 1 < tmp - pos)||((abs(dp[i][1] - dp[i][0]) + 1 <= tmp - pos&&dp[i][1] == -1)))
                    dp[i][1] = pos + 1, dp[i][0] = tmp;
                pos = tmp - 1;
                while(pos >= 0)
                {
                    if(ch2[i] != ch[pos])
                        pos--;
                    else
                        break;
                }
                if(pos == -1)
                    break;
                pos2 = i, tmp = pos;
            }
        }
        if(flag)
        {
            if((abs(dp[i][1] - dp[i][0]) + 1 < tmp - pos)||((abs(dp[i][1] - dp[i][0]) + 1 <= tmp - pos&&dp[i][1] == -1)))
                dp[i][1] = pos + 1, dp[i][0] = tmp;
        }
    }
    int nn = 0;
    flag = 0;
    for(int i = 0;i < len2;i++)
    {
        ans[nn][0] = dp[i][0];
        ans[nn++][1] = dp[i][1];
        if(dp[i][0] == -1||dp[i][1] == -1)
        {
            flag = 1;
            break;
        }
        i = i + abs(dp[i][0] - dp[i][1]);
    }
    if(flag)
    {
        printf("-1\n");
        return 0;
    }
    printf("%d\n", nn);
    for(int i = 0;i < nn;i++)
        printf("%d %d\n", ans[i][0] + 1, ans[i][1] + 1);
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline ll input(void)
{
	char t;
	ll x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(ll x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar('\n');
}

map <ll, pii> m;
set <ll> hashmap;
vector<pii> indices;

int main()
{
	ll x,y,flag=0,sz,n;
	string s,t;
	cin >> s;
	cin >> t;
	n=s.length();
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	REP(i,t.length())
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		REP(i,indices.size())
			printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 10000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline int input(void)
{
	char t;
	int x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(int x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar('\n');
}

map <int, pii> m;
set <int> hashmap;
vector <pii> indices;

int main()
{
	int x,y,flag=0,sz,n,mq;
	string s,t;
	cin >> s;
	cin >> t;
	n=s.length();
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	mq=t.length();
	REP(i,mq)
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			if (x>=mod) x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		REP(i,indices.size())
			printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 2210
#define MAX 30
#define mod 10000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline int input(void)
{
	char t;
	int x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(int x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar(' ');
}

map <int, pii> m;
set <int> hashmap;
vector <pii> indices;
char s[N],t[N];

int main()
{
	int x,y,flag=0,sz,n,mq;
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s);
	mq=strlen(t);
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			if (hashmap.find(x)==hashmap.end())
			{
				hashmap.insert(x);
				m[x]=mp(i,j);
			}
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			if (hashmap.find(x)==hashmap.end())
			{
				hashmap.insert(x);
				m[x]=mp(i,j);
			}
		}
	REP(i,mq)
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			if (x>=mod) x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		putchar('\n');
		REP(i,indices.size())
		{
			output(indices[i].X+1);
			output(indices[i].Y+1);
			putchar('\n');
		}
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline ll input(void)
{
	char t;
	ll x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(ll x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar('\n');
}

map <ll, pii> m;
set <ll> hashmap;
vector <pii> indices;

int main()
{
	ll x,y,flag=0,sz,n,mq;
	string s,t;
	cin >> s;
	cin >> t;
	n=s.length();
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	mq=t.length();
	REP(i,mq)
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			if (x>=mod) x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		REP(i,indices.size())
			printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 2210
#define MAX 30
#define mod 10000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline int input(void)
{
	char t;
	int x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(int x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar('\n');
}

map <int, pii> m;
set <int> hashmap;
vector <pii> indices;
char s[N],t[N];

int main()
{
	int x,y,flag=0,sz,n,mq;
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s);
	mq=strlen(t);
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	REP(i,mq)
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			if (x>=mod) x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		REP(i,indices.size())
			printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline ll input(void)
{
	char t;
	ll x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(ll x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar('\n');
}

map <ll, pii> m;
set <ll> hashmap;
vector <pii> indices;

int main()
{
	ll x,y,flag=0,sz,n,m=t.length();
	string s,t;
	cin >> s;
	cin >> t;
	n=s.length();
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	REP(i,m)
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			if (x>=mod) x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		REP(i,indices.size())
			printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 2210
#define MAX 30
#define mod 10000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline int input(void)
{
	char t;
	int x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(int x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar(' ');
}

int main()
{
	map <int, pii> m;
	set <int> hashmap;
	vector <pii> indices;
	char s[N],t[N];
	int x,y,flag=0,sz,n,mq;
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s);
	mq=strlen(t);
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			if (hashmap.find(x)==hashmap.end())
			{
				hashmap.insert(x);
				m[x]=mp(i,j);
			}
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			if (hashmap.find(x)==hashmap.end())
			{
				hashmap.insert(x);
				m[x]=mp(i,j);
			}
		}
	REP(i,mq)
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			if (x>=mod) x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		putchar('\n');
		REP(i,indices.size())
		{
			output(indices[i].X+1);
			output(indices[i].Y+1);
			putchar('\n');
		}
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 2210
#define MAX 30
#define mod 10000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline int input(void)
{
	char t;
	int x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(int x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar('\n');
}

map <int, pii> m;
set <int> hashmap;
vector <pii> indices;
char s[N],t[N];

int main()
{
	int x,y,flag=0,sz,n,mq;
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s);
	mq=strlen(t);
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			if (hashmap.find(x)==hashmap.end())
			{
				hashmap.insert(x);
				m[x]=mp(i,j);
			}
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			if (hashmap.find(x)==hashmap.end())
			{
				hashmap.insert(x);
				m[x]=mp(i,j);
			}
		}
	REP(i,mq)
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			if (x>=mod) x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		REP(i,indices.size())
			printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline ll input(void)
{
	char t;
	ll x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(ll x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar('\n');
}

map <ll, pii> m;
set <ll> hashmap;
vector<pii> indices;

int main()
{
	ll x,y,flag=0,sz,n;
	string s,t;
	cin >> s;
	cin >> t;
	n=s.length();
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	REP(i,t.length())
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		REP(i,indices.size())
			printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 3010
#define MAX 30
#define mod 10000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline int input(void)
{
	char t;
	int x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(int x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar('\n');
}

map <int, pii> m;
set <int> hashmap;
vector <pii> indices;
char s[N],t[N];

int main()
{
	int x,y,flag=0,sz,n,mq;
	n=strlen(s);
	mq=strlen(t);
	REP(i,n)
		REPP(j,i,n)
		{
			if (j==i)
				x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	for(int i=n-1;i>=0;i--)
		for(int j=i;j>=0;j--)
		{
			if (j==i) x=s[i]-'a'+1;
			else x=27*x+(s[j]-'a'+1);
			if (x>=mod) x%=mod;
			hashmap.insert(x);
			m[x]=mp(i,j);
		}
	REP(i,mq)
	{
		x=t[i]-'a'+1;
		y=-1;
		while(hashmap.find(x)!=hashmap.end())
		{
			y=x;
			i++;
			x=27*x+t[i]-'a'+1;
			if (x>=mod) x%=mod;
		}
		if (y==-1)
		{
			flag=1;
			break;
		}
		else indices.pb(m[y]);
		i--;
	}
	if (flag) printf("-1\n");
	else
	{
		sz=indices.size();
		output(sz);
		REP(i,indices.size())
			printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
	}
return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define	mp make_pair
#define	pb push_back
#define	X first
#define	Y second
#define sz(a) int((a).size())
#define N 2210
#define MAX 30
#define mod 10000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

inline int input(void)
{
	char t;
	int x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
	while(t>=48 && t<=57)
	{
		x=(x<<3)+(x<<1)+t-48;
		t=getchar();
	}
	if (neg) x=-x;
	return x;
}

inline void output(int x)
{
	char a[20];
	int i=0,j;
	a[0]='0';
	if (x<0) {putchar('-'); x=-x;}
	if (x==0) putchar('0');
	while(x)
	{
		a[i++]=x%10+48;
		x/=10;
	}
	for(j=i-1;j>=0;j--)
	{
		putchar(a[j]);
	}
	putchar(' ');
}

int trie[27][(N*N+N)/2],revtrie[27][(N*N+N)/2],unused;
vector <pii> indices;

int main()
{
	char s[N],t[N];
	int sz,n,m,pres[2][26],curr,x;
	pii a,b;
	FILL(pres,0);
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s);
	m=strlen(t);
	REP(i,n) pres[0][s[i]-'a']=1;
	REP(i,m) pres[1][t[i]-'a']=1;
	REP(i,26)
		if (pres[1][i]&&!pres[0][i])
		{
			printf("-1\n");
			return 0;
		}
	unused=1;
	REP(i,26) trie[i][0]=-1;
	REP(i,n)
	{
		curr=0;
		REPP(j,i,n)
		{
			if (trie[s[j]-'a'][curr]==-1)
			{
				trie[s[j]-'a'][curr]=unused;
				REP(k,26) trie[k][unused]=-1;
				curr=unused;
				unused++;
			}
			else curr=trie[s[j]-'a'][curr];
			trie[26][curr]=i;
		}
	}
	unused=1;
	REP(i,26) revtrie[i][0]=-1;
	for(int i=n-1;i>=0;i--)
	{
		curr=0;
		for(int j=i;j>=0;j--)
		{
			if (revtrie[s[j]-'a'][curr]==-1)
			{
				revtrie[s[j]-'a'][curr]=unused;
				REP(k,26) revtrie[k][unused]=-1;
				curr=unused;
				unused++;
			}
			else curr=revtrie[s[j]-'a'][curr];
			revtrie[26][curr]=i;
		}
	}
	REP(i,m)
	{
		x=i;
		curr=0;
		while(i<m&&trie[t[i]-'a'][curr]!=-1)
		{
			curr=trie[t[i]-'a'][curr];
			i++;
		}
		a.X=i-x;
		a.Y=trie[26][curr];
		i=x;
		curr=0;
		while(i<m&&revtrie[t[i]-'a'][curr]!=-1)
		{
			curr=revtrie[t[i]-'a'][curr];
			i++;
		}
		if (i-x>a.X)
		{
			indices.pb(mp(revtrie[26][curr],revtrie[26][curr]-i+x+1));
			i--;
		}
		else
		{
			indices.pb(mp(a.Y,a.Y+a.X-1));
			i=a.X+x-1;
		}
	}
	sz=indices.size();
	output(sz);
	putchar('\n');
	REP(i,sz) printf("%d %d\n",indices[i].X+1,indices[i].Y+1);
return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define len(n) n.length()
#define mp make_pair
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;i++)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define fre     freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define vll vector<long long int>
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define g2(m,n) cin >> m >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define onn printf("\n")
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define alll(n,i,j) n.begin()+i,n.begin()+j
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define mem(n,m) memset(n,m,sizeof(n))
#define bitc(n) __builtin_popcount(n)
#define mod 1000000007
#define ma(m,n) m = max(m,n)
#define mi(m,n) m = min(m,n)
#define EPSILON 1e-9
#define PI 3.14159265358979323846

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;
#define N 100005

map<string, pair<int,int> > Map;
map<string, bool > is;

int main(){
	boost;
	string s,t;
	cin >> s >> t;
	int sz = len(s);
	rep(i,sz){
		string w = "";
		forp(j,i,sz-1){
			w += s[j];
			Map[w] = mp(i,j);
			is[w] = true;
		}
	}
	reverse(all(s));
	rep(i,sz){
		string w = "";
		forp(j,i,sz-1){
			w += s[j];
			Map[w] = mp(j,i);
			is[w] = true;
		}
	}
	vector<pair <int ,int> > ans;
	sz = len(t);
	string w = "";
	int st = -1,en = -1;
	rep(i,sz){
		w += t[i];
		if(is[w]){
			st = Map[w].ff;
			en = Map[w].ss;
		} else if(st+en == -2){
			cout << "-1";
			return 0;
		} else {
			ans.pb(mp(st+1,en+1));
			st = en = -1;
			w = t[i];
		}
	}
	ans.pb(mp(st+1,en+1));
	sz = ans.size();
	cout << sz << "\n";
	rep(i,sz){
		cout << ans[i].ff << " " << ans[i].ss << "\n";
	}
    return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define len(n) n.length()
#define mp make_pair
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;i++)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define fre     freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define vll vector<long long int>
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define g2(m,n) cin >> m >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define onn printf("\n")
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define alll(n,i,j) n.begin()+i,n.begin()+j
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define mem(n,m) memset(n,m,sizeof(n))
#define bitc(n) __builtin_popcount(n)
#define mod 1000000007
#define ma(m,n) m = max(m,n)
#define mi(m,n) m = min(m,n)
#define EPSILON 1e-9
#define PI 3.14159265358979323846

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;
#define N 100005

vector<pair<int ,int> > ans;

int main(){
    boost;
    string s,t;
    cin >> s >> t;
    s = "7" + s + "7";
    string r = s;
    reverse(all(r));
    int szs = len(s)-1;
    int szt = len(t);
    string w = "";
    int st = -1,en = -1;
    rep(i,szt){
        w += t[i];
        int found = s.find(w);
        if(found == -1){
            found = r.find(w);
        } else {
            st = found;
            en = found+w.size()-1;
            continue;
        }
        if(found == -1){
            if(w.size() == 1){
                cout << "-1";
                return 0;
             } else {
                --i;
                ans.pb(mp(st,en));
                w = "";
             }
         } else {
            st = found;
            en = found + w.size()-1;
            st = szs-st;
            en = szs-en;
         }
    }
    ans.pb(mp(st,en));
    int sz = ans.size();
    cout << sz << "\n";
    rep(i,sz){
        cout << ans[i].ff << " " << ans[i].ss << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define len(n) n.length()
#define mp make_pair
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;i++)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define fre     freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define vll vector<long long int>
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define g2(m,n) cin >> m >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define onn printf("\n")
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define alll(n,i,j) n.begin()+i,n.begin()+j
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define mem(n,m) memset(n,m,sizeof(n))
#define bitc(n) __builtin_popcount(n)
#define mod 1000000007
#define ma(m,n) m = max(m,n)
#define mi(m,n) m = min(m,n)
#define EPSILON 1e-9
#define PI 3.14159265358979323846

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;
#define N 100005

map<string, pair<int,int> > Map;
map<string, bool > is;

int main(){
    boost;
    string s,t;
    cin >> s >> t;
    int sz = len(s);
    rep(i,sz){
        string w = "";
        forp(j,i,sz-1){
            w += s[j];
            if(!is[w]){
                Map[w] = mp(i,j);
                is[w] = true;
            }
        }
    }
    reverse(all(s));
    rep(i,sz){
        string w = "";
        forp(j,i,sz-1){
            w += s[j];
            if(!is[w]){
                Map[w] = mp(sz-1-i,sz-1-j);
                is[w] = true;
            }
        }
    }
    vector<pair <int ,int> > ans;
    sz = len(t);
    string w = "";
    int st = -1,en = -1;
    rep(i,sz){
        w += t[i];
        if(is[w]){
            st = Map[w].ff;
            en = Map[w].ss;
        } else if(st+en == -2){
            cout << "-1";
            return 0;
        } else {
            ans.pb(mp(st+1,en+1));
            st = en = -1;
            w = "";
            --i;
        }
    }
    ans.pb(mp(st+1,en+1));
    sz = ans.size();
    cout << sz << "\n";
    rep(i,sz){
        cout << ans[i].ff << " " << ans[i].ss << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define len(n) n.length()
#define mp make_pair
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;i++)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define fre     freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define vll vector<long long int>
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define g2(m,n) cin >> m >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define onn printf("\n")
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define alll(n,i,j) n.begin()+i,n.begin()+j
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define mem(n,m) memset(n,m,sizeof(n))
#define bitc(n) __builtin_popcount(n)
#define mod 1000000007
#define ma(m,n) m = max(m,n)
#define mi(m,n) m = min(m,n)
#define EPSILON 1e-9
#define PI 3.14159265358979323846

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;
#define N 100005

map<string, pair<int,int> > Map;
map<string, bool > is;

int main(){
    boost;
    string s,t;
    cin >> s >> t;
    int sz = len(s);
    rep(i,sz){
        string w = "";
        forp(j,i,sz-1){
            w += s[j];
            if(!is[w]){
                Map[w] = mp(i,j);
                is[w] = true;
            }
        }
    }
    reverse(all(s));
    rep(i,sz){
        string w = "";
        forp(j,i,sz-1){
            w += s[j];
            if(!is[w]){
                Map[w] = mp(sz-1-i,sz-1-j);
                is[w] = true;
            }
        }
    }
    vector<pair <int ,int> > ans;
    sz = len(t);
    string w = "";
    int st = -1,en = -1;
    rep(i,sz){
        w += t[i];
        if(is[w]){
            st = Map[w].ff;
            en = Map[w].ss;
        } else if(st+en == -2){
            cout << "-1";
            return 0;
        } else {
            ans.pb(mp(st+1,en+1));
            st = en = -1;
            w = t[i];
        }
    }
    ans.pb(mp(st+1,en+1));
    sz = ans.size();
    cout << sz << "\n";
    rep(i,sz){
        cout << ans[i].ff << " " << ans[i].ss << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define len(n) n.length()
#define mp make_pair
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;i++)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define fre     freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define vll vector<long long int>
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define g2(m,n) cin >> m >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define onn printf("\n")
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define alll(n,i,j) n.begin()+i,n.begin()+j
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define mem(n,m) memset(n,m,sizeof(n))
#define bitc(n) __builtin_popcount(n)
#define mod 1000000007
#define ma(m,n) m = max(m,n)
#define mi(m,n) m = min(m,n)
#define EPSILON 1e-9
#define PI 3.14159265358979323846

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;
#define N 100005

vector<pair<int ,int> > ans;

int main(){
    boost;
    string s,t;
    cin >> s >> t;
    s = "7" + s + "7";
    string r = s;
    reverse(all(r));
    int szs = len(s)-1;
    int szt = len(t);
    string w = "";
    int st = -1,en = -1;
    rep(i,szt){
        w += t[i];
        int found = s.find(w);
        if(found == -1){
            found = r.find(w);
        } else {
            st = found;
            en = found+w.size()-1;
            continue;
        }
        if(found == -1){
            if(w.size() == 1){
                cout << 1;
                return 0;
             } else {
                --i;
                ans.pb(mp(st,en));
                w = "";
             }
         } else {
            st = found;
            en = found + w.size()-1;
            st = szs-st;
            en = szs-en;
         }
    }
    ans.pb(mp(st,en));
    int sz = ans.size();
    cout << sz << "\n";
    rep(i,sz){
        cout << ans[i].ff << " " << ans[i].ss << "\n";
    }
    return 0;
}


/*
ID: ashish1610
PROG:
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
#define ll              long long int
#define MOD             1000000007
#define si(a)           scanf("%d", &a)
#define sl(a)           scanf("%lld", &a)
#define pi(a)           printf("%d", a)
#define pl(a)           printf("%lld", a)
#define pn              printf("\n")
ll pow_mod(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
bool flag[26];
int main() {
    string str1, str2;
    cin >> str1 >> str2;
    for(int i = 0; i < (int)(str1.length()); ++i) {
        flag[str1[i] - 'a'] = true;
    }
    bool check = true;
    for(int i = 0; i < (int)(str2.length()); ++i) {
        if(!flag[str2[i] - 'a']) {
            check = false;
            break;
        }
    }
    if(!check) {
        printf("-1\n");
    } else {
        int idx = 0;
        string tmp = "";
        vector<pair<int, int> >res;
        int prev_st = 0, prev_end = 0;
        while(idx < (int)(str2.length())) {
            tmp.push_back(str2[idx]);
            string tmp1 = tmp;
            reverse(tmp1.begin(), tmp1.end());
            if(str1.find(tmp) != string::npos) {
                // cout << tmp << endl;
                prev_st = (int)(str1.find(tmp));
                prev_end = prev_st + (int)(tmp.length()) - 1;
            } else if(str1.find(tmp1) != string::npos) {
                // cout << tmp1 << endl;
                prev_end = (int)(str1.find(tmp1));
                prev_st = prev_end + (int)(tmp1.length()) - 1;
            } else {
                res.push_back(make_pair(prev_st, prev_end));
                tmp = str2[idx];
                prev_st = (int)(str1.find(tmp));
                prev_end = prev_st;
            }
            idx++;
        }
        res.push_back(make_pair(prev_st, prev_end));
        pi((int)(res.size()));
        pn;
        string ans = "";
        for(int i = 0; i < (int)(res.size()); ++i) {
            if(res[i].first <= res[i].second) {
                for(int j = res[i].first; j <= res[i].second; ++j) {
                    ans.push_back(str1[j]);
                }
            } else {
                for(int j = res[i].first; j >= res[i].second; --j) {
                    ans.push_back(str1[j]);
                }
            }
            pi(res[i].first + 1);
            printf(" ");
            pi(res[i].second + 1);
            pn;
        }
        assert(ans == str2);
    }
    return 0;
}


/*
ID: ashish1610
PROG:
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
#define ll              long long int
#define MOD             1000000007
#define si(a)           scanf("%d", &a)
#define sl(a)           scanf("%lld", &a)
#define pi(a)           printf("%d", a)
#define pl(a)           printf("%lld", a)
#define pn              printf("\n")
ll pow_mod(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
bool flag[26];
int main() {
    string str1, str2;
    cin >> str1 >> str2;
    for(int i = 0; i < (int)(str1.length()); ++i) {
        flag[str1[i] - 'a'] = true;
    }
    bool check = true;
    for(int i = 0; i < (int)(str2.length()); ++i) {
        if(!flag[str2[i] - 'a']) {
            check = false;
            break;
        }
    }
    if(!check) {
        printf("-1\n");
    } else {
        int idx = 0;
        string tmp = "";
        vector<pair<int, int> >res;
        int prev_st = 0, prev_end = 0;
        while(idx < (int)(str2.length())) {
            tmp.push_back(str2[idx]);
            string tmp1 = tmp;
            reverse(tmp1.begin(), tmp1.end());
            if(str1.find(tmp) != string::npos) {
                prev_st = (int)(str1.find(tmp));
                prev_end = prev_st + (int)(tmp.length()) - 1;
            } else if(str1.find(tmp1) != string::npos) {
                prev_end = (int)(str1.find(tmp1));
                prev_st = prev_end + (int)(tmp1.length()) - 1;
            } else {
                res.push_back(make_pair(prev_st, prev_end));
                prev_st = idx;
                prev_end = idx;
                tmp = str2[idx];
            }
            idx++;
        }
        res.push_back(make_pair(prev_st, prev_end));
        pi((int)(res.size()));
        pn;
        string ans = "";
        for(int i = 0; i < (int)(res.size()); ++i) {
            if(res[i].first <= res[i].second) {
                for(int j = res[i].first; j <= res[i].second; ++j) {
                    ans.push_back(str1[j]);
                }
            } else {
                for(int j = res[i].first; j >= res[i].second; --j) {
                    ans.push_back(str1[j]);
                }
            }
            pi(res[i].first + 1);
            printf(" ");
            pi(res[i].second + 1);
            pn;
        }
        assert(ans == str2);
    }
    return 0;
}


/*
ID: ashish1610
PROG:
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
#define ll              long long int
#define MOD             1000000007
#define si(a)           scanf("%d", &a)
#define sl(a)           scanf("%lld", &a)
#define pi(a)           printf("%d", a)
#define pl(a)           printf("%lld", a)
#define pn              printf("\n")
ll pow_mod(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
bool flag[26];
int main() {
    string str1, str2;
    cin >> str1 >> str2;
    for(int i = 0; i < (int)(str1.length()); ++i) {
        flag[str1[i] - 'a'] = true;
    }
    bool check = true;
    for(int i = 0; i < (int)(str2.length()); ++i) {
        if(!flag[str2[i] - 'a']) {
            check = false;
            break;
        }
    }
    if(!check) {
        printf("-1\n");
    } else {
        int idx = 0;
        string tmp = "";
        vector<pair<int, int> >res;
        int prev_st = 0, prev_end = 0;
        while(idx < (int)(str2.length())) {
            tmp.push_back(str2[idx]);
            string tmp1 = tmp;
            reverse(tmp1.begin(), tmp1.end());
            if(str1.find(tmp) != string::npos) {
                // cout << tmp << endl;
                prev_st = (int)(str1.find(tmp));
                prev_end = prev_st + (int)(tmp.length()) - 1;
            } else if(str1.find(tmp1) != string::npos) {
                // cout << tmp1 << endl;
                prev_end = (int)(str1.find(tmp1));
                prev_st = prev_end + (int)(tmp1.length()) - 1;
            } else {
                res.push_back(make_pair(prev_st, prev_end));
                prev_st = idx;
                prev_end = idx;
                tmp = str2[idx];
            }
            idx++;
        }
        string tmp1 = tmp;
        reverse(tmp1.begin(), tmp1.end());
        if(str1.find(tmp) != string::npos) {
            prev_st = (int)(str1.find(tmp));
            prev_end = prev_st + (int)(tmp.length()) - 1;
        } else if(str1.find(tmp1) != string::npos) {
            prev_end = (int)(str1.find(tmp1));
            prev_st = prev_end + (int)(tmp1.length()) - 1;
        }
        res.push_back(make_pair(prev_st, prev_end));
        pi((int)(res.size()));
        pn;
        string ans = "";
        for(int i = 0; i < (int)(res.size()); ++i) {
            if(res[i].first <= res[i].second) {
                for(int j = res[i].first; j <= res[i].second; ++j) {
                    ans.push_back(str1[j]);
                }
            } else {
                for(int j = res[i].first; j >= res[i].second; --j) {
                    ans.push_back(str1[j]);
                }
            }
            pi(res[i].first + 1);
            printf(" ");
            pi(res[i].second + 1);
            pn;
        }
        assert(ans == str2);
    }
    return 0;
}


/*
ID: ashish1610
PROG:
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
#define ll              long long int
#define MOD             1000000007
#define si(a)           scanf("%d", &a)
#define sl(a)           scanf("%lld", &a)
#define pi(a)           printf("%d", a)
#define pl(a)           printf("%lld", a)
#define pn              printf("\n")
ll pow_mod(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
bool flag[26];
int main() {
    string str1, str2;
    cin >> str1 >> str2;
    for(int i = 0; i < (int)(str1.length()); ++i) {
        flag[str1[i] - 'a'] = true;
    }
    bool check = true;
    for(int i = 0; i < (int)(str2.length()); ++i) {
        if(!flag[str2[i] - 'a']) {
            check = false;
            break;
        }
    }
    if(!check) {
        printf("-1\n");
    } else {
        int idx = 0;
        string tmp = "";
        vector<pair<int, int> >res;
        int prev_st = 0, prev_end = 0;
        while(idx < (int)(str2.length())) {
            tmp.push_back(str2[idx]);
            string tmp1 = tmp;
            reverse(tmp1.begin(), tmp1.end());
            if(str1.find(tmp) != string::npos) {
                // cout << tmp << endl;
                prev_st = (int)(str1.find(tmp));
                prev_end = prev_st + (int)(tmp.length()) - 1;
            } else if(str1.find(tmp1) != string::npos) {
                // cout << tmp1 << endl;
                prev_end = (int)(str1.find(tmp1));
                prev_st = prev_end + (int)(tmp1.length()) - 1;
            } else {
                res.push_back(make_pair(prev_st, prev_end));
                prev_st = idx;
                prev_end = idx;
                tmp = str2[idx];
            }
            idx++;
        }
        string tmp1 = tmp;
        reverse(tmp1.begin(), tmp1.end());
        if(str1.find(tmp) != string::npos) {
            prev_st = (int)(str1.find(tmp));
            prev_end = prev_st + (int)(tmp.length()) - 1;
        } else if(str1.find(tmp1) != string::npos) {
            prev_end = (int)(str1.find(tmp1));
            prev_st = prev_end + (int)(tmp1.length()) - 1;
        }
        res.push_back(make_pair(prev_st, prev_end));
        pi((int)(res.size()));
        pn;
        // string ans = "";
        for(int i = 0; i < (int)(res.size()); ++i) {
            // if(res[i].first <= res[i].second) {
            //  for(int j = res[i].first; j <= res[i].second; ++j) {
            //      ans.push_back(str1[j]);
            //  }
            // } else {
            //  for(int j = res[i].first; j >= res[i].second; --j) {
            //      ans.push_back(str1[j]);
            //  }
            // }
            pi(res[i].first + 1);
            printf(" ");
            pi(res[i].second + 1);
            pn;
        }
        // assert(ans == str2);
    }
    return 0;
}


/*
ID: ashish1610
PROG:
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
#define ll              long long int
#define MOD             1000000007
#define si(a)           scanf("%d", &a)
#define sl(a)           scanf("%lld", &a)
#define pi(a)           printf("%d", a)
#define pl(a)           printf("%lld", a)
#define pn              printf("\n")
ll pow_mod(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
bool flag[26];
int main() {
    string str1, str2;
    cin >> str1 >> str2;
    for(int i = 0; i < (int)(str1.length()); ++i) {
        flag[str1[i] - 'a'] = true;
    }
    bool check = true;
    for(int i = 0; i < (int)(str2.length()); ++i) {
        if(!flag[str2[i] - 'a']) {
            check = false;
            break;
        }
    }
    if(!check) {
        printf("-1\n");
    } else {
        int idx = 0;
        string tmp = "";
        vector<pair<int, int> >res;
        int prev_st = 0, prev_end = 0;
        while(idx < (int)(str2.length())) {
            tmp.push_back(str2[idx]);
            string tmp1 = tmp;
            reverse(tmp1.begin(), tmp1.end());
            if(str1.find(tmp) != string::npos) {
                prev_st = (int)(str1.find(tmp));
                prev_end = prev_st + (int)(tmp.length()) - 1;
            } else if(str1.find(tmp1) != string::npos) {
                prev_end = (int)(str1.find(tmp1));
                prev_st = prev_end + (int)(tmp1.length()) - 1;
            } else {
                res.push_back(make_pair(prev_st, prev_end));
                prev_st = idx;
                prev_end = idx;
                tmp = str2[idx];
            }
            idx++;
        }
        res.push_back(make_pair(prev_st, prev_end));
        pi((int)(res.size()));
        pn;
        for(int i = 0; i < (int)(res.size()); ++i) {
            pi(res[i].first + 1);
            printf(" ");
            pi(res[i].second + 1);
            pn;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int len,L,N,Pre[5805];
char s[5805],t[5805];
int ans,d[5985][3];
int main()
{

	scanf("%s",s+1);
	len=strlen(s+1);	L=len;
	s[len+1]='#';
	for (int i=1;i<=len;++i) s[i+len+1]=s[len-i+1];
	len=len*2+1;
	scanf("%s",t+1);
	N=strlen(t+1);
	int st=0,X,Y;
	for (int i=1,j=0;i<=N;) {
		if (i-st>1) {
			//j=max(j,st);
			while (j>st&&t[j+1]!=t[i]) j=Pre[j];
			if (t[j+1]==t[i]) ++j;
			Pre[i]=j;
		}
		bool boo=0;
		int k,l,last;
		for (k=1,l=st;k<=len;++k) {
			//l=max(l,st);
			while (l>st&&t[l+1]!=s[k]) l=Pre[l];
			if (t[l+1]==s[k]) ++l;
			if (l==i) {
				last=k-i+st+1;
				boo=1; break;
			}
		}
		if (!boo) {
			if (i-st==1) { ans=-1; break; }
			d[++ans][0]=X; d[ans][1]=Y;
			st=j=i-1;	Pre[i]=st;
		} else {
			++i;
			if (last>L) {
				last=len-last+1; k=len-k+1;
			}
			X=last; Y=k;
		}
	}
	if (ans>=0) d[++ans][0]=X; d[ans][1]=Y;
	printf("%d\n",ans);
	for (int i=1;i<=ans;++i) {
		printf("%d %d\n",d[i][0],d[i][1]);
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int len,L,N,Pre[5805];
char s[5805],t[5805];
int ans,d[5985][3];
int main()
{

	scanf("%s",s+1);
	len=strlen(s+1);	L=len;
	s[len+1]='#';
	for (int i=1;i<=len;++i) s[i+len+1]=s[len-i+1];
	len=len*2+1;
	scanf("%s",t+1);
	N=strlen(t+1);
	int st=0,X,Y;
	for (int i=1,j=0;i<=N;) {
		if (i-j>1) {
			j=max(j,st);
			while (j>st&&t[j+1]!=t[i]) j=Pre[j];
			if (t[j+1]==t[i]) ++j;
			Pre[i]=j;
		}
		bool boo=0;
		int k,l,last;
		for (k=1,l=st;k<=len;++k) {
			l=max(l,st);
			while (l>st&&t[l+1]!=s[k]) l=Pre[l];
			if (t[l+1]==s[k]) ++l;
			if (l==st+1) last=k;
			if (l==i) {
				boo=1; break;
			}
		}
		if (!boo) {
			if (i-st==1) { ans=-1; break; }
			d[++ans][0]=X; d[ans][1]=Y;
			st=j=i-1;	Pre[i]=st;
		} else {
			++i;
			if (last>L) {
				last=len-last+1; k=len-k+1;
			}
			X=last; Y=k;
		}
	}
	if (ans>=0) d[++ans][0]=X; d[ans][1]=Y;
	printf("%d\n",ans);
	for (int i=1;i<=ans;++i) {
		printf("%d %d\n",d[i][0],d[i][1]);
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int len,L,N,Pre[5805];
char s[5805],t[5805];
int ans,d[5985][3];
int main()
{

	scanf("%s",s+1);
	len=strlen(s+1);	L=len;
	s[len+1]='#';
	for (int i=1;i<=len;++i) s[i+len+1]=s[len-i+1];
	len=len*2+1;
	scanf("%s",t+1);
	N=strlen(t+1);
	int st=0,X,Y;
	for (int i=1,j=0;i<=N;) {
		if (i-st>1) {
			//j=max(j,st);
			while (j>st&&t[j+1]!=t[i]) j=Pre[j];
			if (t[j+1]==t[i]) ++j;
			Pre[i]=j;
		}
		bool boo=0;
		int k,l,last;
		for (k=1,l=st;k<=len;++k) {
			//l=max(l,st);
			while (l>st&&t[l+1]!=s[k]) l=Pre[l];
			if (t[l+1]==s[k]) ++l;
			if (l==st+1) last=k;
			if (l==i) {
				boo=1; break;
			}
		}
		if (!boo) {
			if (i-st==1) { ans=-1; break; }
			d[++ans][0]=X; d[ans][1]=Y;
			st=j=i-1;	Pre[i]=st;
		} else {
			++i;
			if (last>L) {
				last=len-last+1; k=len-k+1;
			}
			X=last; Y=k;
		}
	}
	if (ans>=0) d[++ans][0]=X; d[ans][1]=Y;
	printf("%d\n",ans);
	for (int i=1;i<=ans;++i) {
		printf("%d %d\n",d[i][0],d[i][1]);
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int len,L,N,Pre[5805];
char s[5805],t[5805];
int ans,d[5985][3];
int main()
{

	scanf("%s",s+1);
	len=strlen(s+1);	L=len;
	s[len+1]='#';
	for (int i=1;i<=len;++i) s[i+len+1]=s[len-i+1];
	len=len*2+1;
	scanf("%s",t+1);
	N=strlen(t+1);
	int st=0,X,Y;
	for (int i=1,j=0;i<=N;) {
		if (i-j>1) {
			j=max(j,st);
			while (j>st&&t[j+1]!=t[i]) j=Pre[j];
			if (t[j+1]==t[i]) ++j;
			Pre[i]=j;
		}
		bool boo=0;
		int k,l,last;
		for (k=1,l=st;k<=len;++k) {
			l=max(l,st);
			while (l>st&&t[l+1]!=s[k]) l=Pre[l];
			if (t[l+1]==s[k]) ++l;
			if (l==st+1) last=k;
			if (l==i) {
				boo=1; break;
			}
		}
		if (!boo) {
			if (i-st==1) { ans=-1; break; }
			d[++ans][0]=X; d[ans][1]=Y;
			st=i-1;	Pre[i]=st;
		} else {
			++i;
			if (last>L) {
				last=len-last+1; k=len-k+1;
			}
			X=last; Y=k;
		}
	}
	if (ans>=0) d[++ans][0]=X; d[ans][1]=Y;
	printf("%d\n",ans);
	for (int i=1;i<=ans;++i) {
		printf("%d %d\n",d[i][0],d[i][1]);
	}
}


#include<bits/stdc++.h>
using namespace std;
string s,t;
long long p[3005];
long long num=47;
long long mod=1000000000007;
map<long long,pair<int,int> >se;
int dp[3005];
pair<int,int>so[3005];
void print(int j)
{
    int l=j-(abs(so[j].second-so[j].first)+1);
    if(l+1==0)
    {
        printf("%d %d\n",so[j].first+1,so[j].second+1);
        return;
    }
    else
    {
        print(l);
        printf("%d %d\n",so[j].first+1,so[j].second+1);
        j=l;
    }
}
int main()
{
    for(int i=0;i<3005;i++)dp[i]=1000000000;
    p[0]=1;
    for(int i=1;i<3005;i++)
        p[i]=(num*p[i-1])%mod;
    cin>>s>>t;
    for(int i=0;i<s.length();i++)
    {
        long long hash=0;
        for(int j=i;j<s.length();j++)
        {
            hash=(hash+(p[j-i]*((s[j]-'a')+1))%mod)%mod;
            se[hash]=make_pair(i,j);
        }
        hash=0;
        for(int j=i;j>=0;j--)
        {
            hash=(hash+(p[i-j]*((s[j]-'a')+1))%mod)%mod;
            se[hash]=make_pair(i,j);
        }
    }
    for(int i=0;i<t.length();i++)
    {
        long long hash=0;
        for(int j=i;j>=0;j--)
        {
            hash=((hash*num)%mod+(((t[j]-'a')+1)))%mod;
            map<long long,pair<int,int> >::iterator it=se.find(hash);
            if(it!=se.end())
            {
                if(j==0)
                {
                    dp[i]=1;
                    so[i]=make_pair(it->second.first,it->second.second);
                }
                else
                {
                    if(dp[j-1]+1<dp[i])
                    {
                        so[i]=make_pair(it->second.first,it->second.second);
                        dp[i]=dp[j-1]+1;
                    }
                }
            }
        }
    }
    if(dp[t.length()-1]==1000000000)
        puts("-1");
    else
    {
        printf("%d\n",dp[t.length()-1]);
        print(t.length()-1);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s,t;
long long p[3005];
long long num=47;
long long mod=1000000000007;
map<long long,pair<int,int> >se;
int dp[3005];
pair<int,int>so[3005];
void print(int j)
{
    int l=j-(abs(so[j].second-so[j].first)+1);
    if(l+1==0)
    {
        printf("%d %d\n",so[j].first+1,so[j].second+1);
        return;
    }
    else
    {
        print(l);
        printf("%d %d\n",so[j].first+1,so[j].second+1);
        j=l;
    }
}
int main()
{
    for(int i=0;i<3005;i++)dp[i]=1000000000;
    p[0]=1;
    for(int i=1;i<3005;i++)
        p[i]=(num*p[i-1])%mod;
    cin>>s>>t;
    for(int i=0;i<s.length();i++)
    {
        long long hash=0;
        for(int j=i;j<s.length();j++)
        {
            hash=(hash+(p[j-i]*((s[j]-'a')+1)))%mod;
            se[hash]=make_pair(i,j);
        }
        hash=0;
        for(int j=i;j>=0;j--)
        {
            hash=(hash+(p[i-j]*((s[j]-'a')+1)))%mod;
            se[hash]=make_pair(i,j);
        }
    }
    for(int i=0;i<t.length();i++)
    {
        long long hash=0;
        for(int j=i;j>=0;j--)
        {
            hash=((hash*num)+(((t[j]-'a')+1)))%mod;
            map<long long,pair<int,int> >::iterator it=se.find(hash);
            if(it!=se.end())
            {
                if(j==0)
                {
                    dp[i]=1;
                    so[i]=make_pair(it->second.first,it->second.second);
                }
                else
                {
                    if(dp[j-1]+1<dp[i])
                    {
                        so[i]=make_pair(it->second.first,it->second.second);
                        dp[i]=dp[j-1]+1;
                    }
                }
            }
        }
    }
    if(dp[t.length()-1]==1000000000)
        puts("-1");
    else
    {
        printf("%d\n",dp[t.length()-1]);
        print(t.length()-1);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
string t;
int dp[2105];
pair<int,int> so[2105];
int trie[2206055][27];
pair<int,int>seg[2206055];
int cur=1;
void print(int j)
{
    int i=j-(abs(so[j].second-so[j].first)+1)+1;
    if(i==0)
    {
        printf("%d %d\n",so[j].first+1,so[j].second+1);
        return;
    }
    print(i-1);
    printf("%d %d\n",so[j].first+1,so[j].second+1);
}
int main()
{
    for(int i=0;i<2105;i++)dp[i]=(1<<30);
    cin>>s>>t;
    for(int i=0;i<s.length();i++)
    {
        int v=1;
        for(int j=i;j<s.length();j++)
        {
            if(trie[v][s[j]-'a']==0)
            {
                cur++;
                seg[cur]=make_pair(i,j);
                trie[v][s[j]-'a']=cur;
                v=cur;
            }
            else
                v=trie[v][s[j]-'a'];
        }
        v=1;
        for(int j=i;j>=0;j--)
        {
            if(trie[v][s[j]-'a']==0)
            {
                cur++;
                seg[cur]=make_pair(i,j);
                trie[v][s[j]-'a']=cur;
                v=cur;
            }
            else
                v=trie[v][s[j]-'a'];
        }
    }
    for(int i=0;i<t.length();i++)
    {
        int v=1;
        for(int j=i;j<t.length();j++)
        {
            if(trie[v][t[j]-'a']==0)break;
            else
            {
                v=trie[v][t[j]-'a'];
                if(i==0)
                {
                    dp[j]=1;
                    so[j]=seg[v];
                }
                else
                {
                    if(dp[j]>dp[i-1]+1)
                    {
                        dp[j]=dp[i-1]+1;
                        so[j]=seg[v];
                    }
                }
            }
        }
    }
    if(dp[t.length()-1]==(1<<30))
        puts("-1");
    else
    {
        printf("%d\n",dp[t.length()-1]);
        print(t.length()-1);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s,t;
long long p[3005];
long long num=43;
long long mod=(1<<12)+7;
map<long long,pair<int,int> >se;
int dp[3005];
pair<int,int>so[3005];
int main()
{
    for(int i=0;i<3005;i++)dp[i]=1000000000;
    p[0]=1;
    for(int i=1;i<3005;i++)
        p[i]=(num*p[i-1])%mod;
    cin>>s>>t;
    for(int i=0;i<s.length();i++)
    {
        long long hash=0;
        for(int j=i;j<s.length();j++)
        {
            hash=(hash+(p[j-i]*((s[j]-'a')+1)))%mod;
            se[hash]=make_pair(i,j);
        }
        hash=0;
        for(int j=i;j>=0;j--)
        {
            hash=(hash+(p[i-j]*((s[j]-'a')+1)))%mod;
            se[hash]=make_pair(i,j);
        }
    }
    for(int i=0;i<t.length();i++)
    {
        long long hash=0;
        int l=0;
        for(int j=i;j>=0;j--)
        {
            hash=((hash*num)+((t[j]-'a'+1)))%mod;
            map<long long,pair<int,int> >::iterator it=se.find(hash);
            if(it!=se.end())
            {
                if(j==0)
                {
                    dp[i]=1;
                    so[i]=make_pair(it->second.first,it->second.second);
                }
                else
                {
                    if(dp[j-1]+1<dp[i])
                    {
                        so[i]=make_pair(it->second.first,it->second.second);
                        dp[i]=min(dp[i],dp[j-1]+1);
                    }
                }
            }
        }
    }
    if(dp[t.length()-1]==1000000000)
        puts("-1");
    else
    {
        printf("%d\n",dp[t.length()-1]);
        int j=t.length()-1;
        while(true)
        {
            int l=j-(abs(so[j].second-so[j].first)+1);
            if(l+1==0)
            {
                printf("%d %d\n",so[j].first+1,so[j].second+1);
                break;
            }
            else
            {
                printf("%d %d\n",so[j].first+1,so[j].second+1);
                j=l;
            }
        }
    }
    return 0;
}