#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith, int j ) {
    //cout<<" "<<ith<<" "<<endl;
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f(  ith + j, j );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {  ++caseno;
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {
          for( int i = 1; i <= 6; i++ ) {
            //cout<<" going with "<<i<<endl;
            for( int j = 1; j<= 4; j++ ) {
                //cout<<" with "<<brr[ j ]<<endl;
              if( f( i, brr[ j ] ) ) {
                mark[ brr[ j ] ] = 1;
              }
            }
          }
          for( int i = 0; i<= 5; i++){ if(mark[brr[ i ]])cnt++; }

          if( caseno == 65 )cout<<crr<<endl;
          printf("%d",cnt);
          if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 4; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}
//OOOOOXOOOOOX
//OOOOOXOOOOOO


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith, int j ) {
    //cout<<" "<<ith<<" "<<endl;
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f(  ith + j, j );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {  ++caseno;
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {
          for( int i = 1; i <= 6; i++ ) {
            //cout<<" going with "<<i<<endl;
            for( int j = 1; j<= 4; j++ ) {
                //cout<<" with "<<brr[ j ]<<endl;
              if( f( i, brr[ j ] ) ) {
                mark[ brr[ j ] ] = 1;
              }
            }
          }
          for( int i = 0; i<= 5; i++){ if(mark[brr[ i ]])cnt++; }

          if( caseno == 99 )cout<<crr<<endl;
          printf("%d",cnt);
          if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 4; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}
//OOOOOXOOOOOX
//OOOOOXOOOOOX
/*
OOOOOXOOOOOO
OOOOOOOXXOXX
OOOOOOOXXXOO
OOOOOOOXXXOX
OOOOOOOXXXXO
OOOOOOOXXXXX
OOOOOOXOOOOO
OOOOOOXOOOOX
OOOOOOXOOOXO
OOOOOOXOOOXX
OOOOOOXOOXOO
OOOOOXOOOOOO
OOOOOXOOOOOX
*/


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith, int j ) {
    //cout<<" "<<ith<<" "<<endl;
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f(  ith + j, j );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {  ++caseno;
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {
          for( int i = 1; i <= 6; i++ ) {
            //cout<<" going with "<<i<<endl;
            for( int j = 1; j<= 4; j++ ) {
                //cout<<" with "<<brr[ j ]<<endl;
              if( ( i < brr[ j ] ) && f( i, brr[ j ] ) ) {
                   mark[ brr[ j ] ] = 1;
              }
            }
          }
          for( int i = 0; i<= 5; i++){ if(mark[brr[ i ]])cnt++; }

          printf("%d",cnt);
          if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 4; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}

//OOOOOXOOOXOO
/*
OOOOOXOOOOOO
OOOOOOOXXOXX
OOOOOOOXXXOO
OOOOOOOXXXOX
OOOOOOOXXXXO
OOOOOOOXXXXX
OOOOOOXOOOOO
OOOOOOXOOOOX
OOOOOOXOOOXO
OOOOOOXOOOXX
OOOOOOXOOXOO
OOOOOXOOOOOO
OOOOOXOOOOOX
*/


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith, int j ) {
    //cout<<" "<<ith<<" "<<endl;
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f(  ith + j, j );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {
          for( int i = 1; i <= 6; i++ ) {
            //cout<<" going with "<<i<<endl;
            for( int j = 1; j<= 4; j++ ) {
                //cout<<" with "<<brr[ j ]<<endl;
              if( f( i, brr[ j ] ) ) {
                mark[ brr[ j ] ] = 1;
              }
            }
          }
          for( int i = 0; i<= 5; i++){ if(mark[brr[ i ]])cnt++; }
          printf("%d",cnt);
          if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 4; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      if( cnt == 2 )cout<<endl<<crr<<endl;
      printf("\n");

    }
    return 0;
}


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith, int j ) {
    //cout<<" "<<ith<<" "<<endl;
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f(  ith + j, j );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {  ++caseno;
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {
          for( int i = 1; i <= 6; i++ ) {
            //cout<<" going with "<<i<<endl;
            for( int j = 1; j<= 4; j++ ) {
                //cout<<" with "<<brr[ j ]<<endl;
              if( f( i, brr[ j ] ) ) {
                mark[ brr[ j ] ] = 1;
              }
            }
          }
          for( int i = 0; i<= 5; i++){ if(mark[brr[ i ]])cnt++; }

          if( caseno == 66 )cout<<crr<<endl;
          printf("%d",cnt);
          if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 4; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}
//OOOOOXOOOOOX
//OOOOOXOOOOOX
/*
OOOOOXOOOOOO
OOOOOOOXXOXX
OOOOOOOXXXOO
OOOOOOOXXXOX
OOOOOOOXXXXO
OOOOOOOXXXXX
OOOOOOXOOOOO
OOOOOOXOOOOX
OOOOOOXOOOXO
OOOOOOXOOOXX
OOOOOOXOOXOO
OOOOOXOOOOOO
OOOOOXOOOOOX
*/


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith, int j ) {
    //cout<<" "<<ith<<" "<<endl;
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f(  ith + j, j );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {
          for( int i = 1; i <= 6; i++ ) {
            //cout<<" going with "<<i<<endl;
            for( int j = 1; j<= 4; j++ ) {
                //cout<<" with "<<brr[ j ]<<endl;
              if( f( i, brr[ j ] ) ) {
                mark[ brr[ j ] ] = 1;
              }
            }
          }
          for( int i = 0; i<= 5; i++){ if(mark[brr[ i ]])cnt++; }
          ++caseno;
          if( caseno == 65 )cout<<endl<<crr<<endl;
          printf("%d",cnt);
          if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 4; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}
//OOOOOXOOOOOX
//OOOOOXOOOOOO


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith, int j ) {
    //cout<<" "<<ith<<" "<<endl;
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f(  ith + j, j );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {  ++caseno;
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {
          for( int i = 1; i <= 6; i++ ) {
            //cout<<" going with "<<i<<endl;
            for( int j = 1; j<= 4; j++ ) {
                //cout<<" with "<<brr[ j ]<<endl;
              if( ( i <= brr[ j ] ) && f( i, brr[ j ] ) ) {
                   mark[ brr[ j ] ] = 1;
              }
            }
          }
          for( int i = 0; i<= 5; i++){ if(mark[brr[ i ]])cnt++; }

          printf("%d",cnt);
          if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 4; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}

//OOOOOXOOOXOO
/*
OOOOOXOOOOOO
OOOOOOOXXOXX
OOOOOOOXXXOO
OOOOOOOXXXOX
OOOOOOOXXXXO
OOOOOOOXXXXX
OOOOOOXOOOOO
OOOOOOXOOOOX
OOOOOOXOOOXO
OOOOOOXOOOXX
OOOOOOXOOXOO
OOOOOXOOOOOO
OOOOOXOOOOOX
*/


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith, int j ) {
    //cout<<" "<<ith<<" "<<endl;
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f(  ith + j, j );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {
          for( int i = 1; i <= 6; i++ ) {
            //cout<<" going with "<<i<<endl;
            for( int j = 1; j<= 4; j++ ) {
                //cout<<" with "<<brr[ j ]<<endl;
              if( f( i, brr[ j ] ) ) {
                mark[ brr[ j ] ] = 1;
              }
            }
          }
          for( int i = 0; i<= 5; i++){ if(mark[brr[ i ]])cnt++; }
          printf("%d",cnt);
          if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 4; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith ) {
    //printf("---%d\n",ith);
    if( ith >= 11 ) return 1;
    if( arr[ ith ] == 'X' ) f( ith + ith );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        cnt = 1;
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {

          for( int i = 1; i <= 4; i++ ) {
            if(!mark[ brr[ i ] ] ) {
                //cout<<" going with "<<brr[ i ]<<endl;
                if( f( brr[ i ] ) ) {
                    cnt++;
                    mark[ brr[ i ] ] = 1;
                    if( brr[ i ] == 2 ) { mark[ 4 ] = mark[ 6 ] = 1; }
                    if( brr[ i ] == 3 ) { mark[ 6 ] = 1; }
                }
            } else {
                cnt++;
            }
          }
          if( cnt == 2 )cout<<crr<<endl;
          printf("%d",cnt); if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 5; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}


#pragma comment(linker,"/STACK:16777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <iterator>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long lint;
const int INF = (1<<29);
#define NN 100010
#define upto 1001

#define CLR( a ) memset( a , 0 , sizeof ( a ) )
#define negCLR( a ) memset( a , -1 , sizeof( a ) )
#define isComposite( a, n ) ( a[ n >> 6 ] & ( 1 << ((n >> 1)&31 ) ) )
#define mark( a, n ) ( a[ n >> 6 ] |= ( 1 << (( n >> 1)&31 ) ) )

char arr[ 14 ];
char crr[ 14 ];
bool mark[ 14 ];
int brr[ 7 ] = { 1, 2, 3, 4, 6, 12 };

int f( int ith ) {
    //printf("---%d\n",ith);
    if( ith > 12 ) return 1;
    if( arr[ ith ] == 'X' ) f( ith + ith );
    else {
        return 0;
    }
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("myout.txt","w",stdout);
    int cases, caseno = 0;
    scanf("%d",&cases);
    while( cases-- ) {
      scanf("%s",&crr);
      CLR( arr );
      int fl = 0, xl = 0;
      for( int i = 0; i < 12; i++) {
        arr[ i + 1 ] = crr[ i ] ;
        if( crr[ i ] != 'X'){ fl = 1; }
        else { xl = 1; }
      }
      int cnt = 0;
      CLR(mark);
      if( xl ) {
        cnt = 1;
        mark[ 1 ] = 1;
      }
      if( !fl && xl ) {
        printf("6 1x12 2x6 3x4 4x3 6x2 12x1");
      } else {

          for( int i = 1; i <= 4; i++ ) {
            if(!mark[ brr[ i ] ] ) {
                //cout<<" going with "<<brr[ i ]<<endl;
                if( f( brr[ i ] ) ) {
                    cnt++;
                    mark[ brr[ i ] ] = 1;
                    if( brr[ i ] == 2 ) { mark[ 4 ] = mark[ 6 ] = 1; }
                    if( brr[ i ] == 3 ) { mark[ 6 ] = 1; }
                }
            } else {
                cnt++;
            }
          }
          //if( cnt == 2 )cout<<crr<<endl;
          printf("%d",cnt); if( mark[ 1 ] ){ printf(" 1x12");}
          for( int i = 5; i >= 1; i--) {
            if( mark[ brr[ i ] ] ) {
                printf(" %dx%d", 12/brr[ i ],brr[ i ] );
            }
          }
      }

      printf("\n");

    }
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int w = 0; w < n; w++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " "
        for (int i = 0; i < tc; i++){
            cout << ans[i] << "x" << 12 / ans[i] << " ";
        }
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int i = 0; i < n; i++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                        }
                        tmp += i;
                    }
                }
                cout << cnt << " " << i << "x" << 12 / i << " ";
            }
        }
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int w = 0; w < n; w++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                bool ch = false;
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    if (ch == true){
                        break;
                    }
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                            tc++;
                            ch = true;
                            break;
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " ";
        for (int i = 0; i < tc; i++){
            cout << ans[i] << "x" << 12 / ans[i] << " ";
        }
        cnt = 0;
        cout << endl;
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int w = 0; w < n; w++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        bool ch = false;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    if (ch == true){
                        break;
                    }
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                            tc++;
                            ch = true;
                            break;
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " ";
        for (int i = 0; i < tc; i++){
            cout << ans[i] << "x" << 12 / ans[i] << " ";
        }
        cnt = 0;
        cout << endl;
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int i = 0; i < n; i++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 & i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                        }
                        tmp += i;
                    }
                }
                cout << cnt << " " << i << "x" << 12 / i << " ";
            }
        }
    }
}


#include <iostream>
#include <string>

using namespace std;

int find(String a){
    for (int i = 1; i <= 12; i++){
        if (12 & i == 0){
            for (int x = 1; x <= i; a++){
                int tmp = x + i;
                while (tmp <= 12){
                    if (a[tmp - 1] != a[tmp - i - 1]){
                        break;
                    }else if (tmp + i > 12){
                        cout << i << "x" << 12 / i << " ";
                    }
                    tmp += i;
                }
            }
        }
    }
}
int main (){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        String t;
        cin >> t;
        find(t);
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int w = 0; w < n; w++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                            tc++
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " ";
        for (int i = 0; i < tc; i++){
            cout << ans[i] << "x" << 12 / ans[i] << " ";
        }
        cnt = 0;
        cout << endl;
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int i = 0; i < n; i++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " "
        for (int i = 0; i < tc; i++){
            cout << ans[i] << "x" << 12 / ans[i] << " ";
        }
    }
}


#include <iostream>

using namespace std;

int find(String a){
    for (int i = 1; i <= 12; i++){
        if (12 & i == 0){
            for (int x = 1; x <= i; a++){
                int tmp = x + i;
                while (tmp <= 12){
                    if (a[tmp - 1] != a[tmp - i - 1]){
                        break;
                    }else if (tmp + i > 12){
                        cout << i << "x" << 12 / i << " ";
                    }
                    tmp += i;
                }
            }
        }
    }
}
int main (){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        String t;
        cin >> t;
        find(t);
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int w = 0; w < n; w++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                            tc++;
                            break;
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " ";
        for (int i = 0; i < tc; i++){
            cout << ans[i] << "x" << 12 / ans[i] << " ";
        }
        cnt = 0;
        cout << endl;
    }
}


#include <iostream>
#include <string>

using namespace std;

int find(char a[]){
    for (int i = 1; i <= 12; i++){
        if (12 & i == 0){
            for (int x = 1; x <= i; a++){
                int tmp = x + i;
                while (tmp <= 12){
                    if (a[tmp - 1] != a[tmp - i - 1]){
                        break;
                    }else if (tmp + i > 12){
                        cout << i << "x" << 12 / i << " ";
                    }
                    tmp += i;
                }
            }
        }
    }
}
int main (){
    int n;
    cin >> n;
    char a[12];
    for (int i = 0; i < n; i++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        find(a);
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int w = 0; w < n; w++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                            tc++;
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " ";
        for (int i = 0; i < tc; i++){
            cout << ans[i] << "x" << 12 / ans[i] << " ";
        }
        cnt = 0;
        cout << endl;
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
int n,t,i,j,A=0,a[15],k;
char s[15];
cin>>t;
while(t--){
      cin>>s;
      for(i=1;i<13;i++){
          if(12%i==0){
             for(j=0;j<i;j++){
                 for(k=j;k<12;k+=i)
                    if(s[k]!='X') break;
             if(k>11){a[A]=i;A++;break;}
             }
          }
      }
      if(A==0) cout<<A<<endl;
      else{cout<<A<<" ";
       for(j=A-1;j>0;j--){cout<<12/a[j]<<"x"<<a[j]<<" ";}
       cout<<12/a[0]<<"x"<<a[0]<<endl;
       A=0;}
}
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int i = 0; i < n; i++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 & i == 0){
                for (int x = 1; x <= i; a++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                        }
                        tmp += i;
                    }
                }
                cout << cnt << " " << i << "x" << 12 / i << " ";
            }
        }
    }
}


#include <iostream>
#include <string>

using namespace std;

string a;

int find(){
    for (int i = 1; i <= 12; i++){
        if (12 & i == 0){
            for (int x = 1; x <= i; a++){
                int tmp = x + i;
                while (tmp <= 12){
                    if (a[tmp - 1] != a[tmp - i - 1]){
                        break;
                    }else if (tmp + i > 12){
                        cout << i << "x" << 12 / i << " ";
                    }
                    tmp += i;
                }
            }
        }
    }
}
int main (){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        find(a);
    }
}


#include <iostream>
#include <string>

using namespace std;

String a;

int find(){
    for (int i = 1; i <= 12; i++){
        if (12 & i == 0){
            for (int x = 1; x <= i; a++){
                int tmp = x + i;
                while (tmp <= 12){
                    if (a[tmp - 1] != a[tmp - i - 1]){
                        break;
                    }else if (tmp + i > 12){
                        cout << i << "x" << 12 / i << " ";
                    }
                    tmp += i;
                }
            }
        }
    }
}
int main (){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        find(a);
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int w = 0; w < n; w++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                bool ch = false;
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    if (ch == true){
                        break;
                    }
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                            tc++;
                            ch = true;
                            break;
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " ";
        for (int i = 0; i < tc; i++){
            cout << 12 / ans[i] << "x" << ans[i] << " ";
        }
        cnt = 0;
        cout << endl;
    }
}


#include <iostream>
#include <string>

using namespace std;

int main (){
    int n;
    cin >> n;
    char a[12];
    for (int w = 0; w < n; w++){
        for (int d = 0; d < 12; d++){
            cin >> a[d];
        }
        int cnt = 0;
        int ans[6];
        int tc = 0;
        for (int i = 1; i <= 12; i++){
            if (12 % i == 0){
                for (int x = 1; x <= i; x++){
                    int tmp = x + i;
                    while (tmp <= 12){
                        if (a[tmp - 1] != a[tmp - i - 1]){
                            break;
                        }else if (tmp + i > 12){
                            cnt++;
                            ans[tc] = i;
                        }
                        tmp += i;
                    }
                }
            }
        }
        cout << cnt << " ";
        for (int i = 0; i < tc; i++){
            cout << ans[i] << "x" << 12 / ans[i] << " ";
        }
    }
}


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

using namespace std;

typedef long long ll;

#define sqr(x) (x)*(x)

int main()
{
    //freopen("data.in","r",stdin); freopen("data.out","w",stdout);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    const int a[]={0,12,6,4,3,2,1};
    int t;
    scanf("%d\n", &t);
    string s;
    int b[111];
    for (int i=1; i<=t; ++i){
        getline(cin,s);
        int kol=0,met;
        for (int j=1; j<7; ++j){
            int l=a[j];
            met=0;
            while (l<12){
                if (s[l-1]!='X') met=1;
                l+=a[j];
            }
            if (!met){
                ++kol;
                b[kol]=a[j];
            }
        }
        cout << kol << ' ';
        for (int j=1; j<=kol; ++j){
            cout << 12/b[j] << 'x' << b[j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

#define sqr(x) (x)*(x)

int main()
{
    //freopen("data.in","r",stdin); freopen("data.out","w",stdout);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    const int a[]={0,12,6,4,3,2,1};
    int t;
    scanf("%d\n", &t);
    string s;
    int b[111],Met[22];
    for (int i=1; i<=t; ++i){
        getline(cin,s);
        int kol=0,met,l;
        for (int j=1; j<7; ++j){
            for (int k=1; k<=12; ++k){
            l=a[j]+k-2;
            l%=12;
            met=0;
            memset(Met,0,sizeof(Met));
            while (!Met[l]){
                if (s[l]!='X') {
                    met=1;
                    break;
                }
                Met[l]=1;
                l=(l+a[j])%12;
            }
            if (!met){
                ++kol;
                b[kol]=a[j];
                break;
            }
            }
        }
        cout << kol << ' ';
        for (int j=1; j<=kol; ++j){
            cout << 12/b[j] << 'x' << b[j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

#define sqr(x) (x)*(x)

int main()
{
    //freopen("data.in","r",stdin); freopen("data.out","w",stdout);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    const int a[]={0,12,6,4,3,2,1};
    int t;
    scanf("%d\n", &t);
    string s;
    int b[111],Met[22];
    for (int i=1; i<=t; ++i){
        getline(cin,s);
        int kol=0,met,l;
        for (int j=1; j<7; ++j){
            for (int k=1; k<=12/a[j]; ++k){
            l=a[j]+k-2;
            met=0;
            memset(Met,0,sizeof(Met));
            while (!Met[l]){
                if (s[l]!='X') {
                    met=1;
                    break;
                }
                Met[l]=1;
                l=(l+a[j])%12;
            }
            if (!met){
                ++kol;
                b[kol]=a[j];
                break;
            }
            }
        }
        cout << kol << ' ';
        for (int j=1; j<=kol; ++j){
            cout << 12/b[j] << 'x' << b[j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

#define sqr(x) (x)*(x)

int main()
{
    //freopen("data.in","r",stdin); freopen("data.out","w",stdout);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    const int a[]={0,12,6,4,3,2,1};
    int t;
    scanf("%d\n", &t);
    string s;
    int b[111];
    for (int i=1; i<=t; ++i){
        getline(cin,s);
        int kol=0,met;
        for (int j=1; j<7; ++j){
            int l=a[j];
            met=0;
            while (l<=12){
                if (s[l-1]!='X') met=1;
                l+=a[j];
            }
            if (!met){
                ++kol;
                b[kol]=a[j];
            }
        }
        cout << kol << ' ';
        for (int j=1; j<=kol; ++j){
            cout << 12/b[j] << 'x' << b[j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

#define sqr(x) (x)*(x)

int main()
{
    //freopen("data.in","r",stdin); freopen("data.out","w",stdout);
    freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    const int a[]={0,12,6,4,3,2,1};
    int t;
    scanf("%d\n", &t);
    string s;
    int b[111],Met[22];
    for (int i=1; i<=t; ++i){
        getline(cin,s);
        int kol=0,met,l;
        for (int j=1; j<7; ++j){
            for (int k=1; k<=12; ++k){
            l=a[j]+k-2;
            l%=12;
            met=0;
            memset(Met,0,sizeof(Met));
            while (!Met[l]){
                if (s[l]!='X') {
                    met=1;
                    break;
                }
                Met[l]=1;
                l=(l+a[j])%12;
            }
            if (!met){
                ++kol;
                b[kol]=a[j];
                break;
            }
            }
        }
        cout << kol << ' ';
        for (int j=1; j<=kol; ++j){
            cout << 12/b[j] << 'x' << b[j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
char str[15];
vector<pii> ans;

void check(int i, int jmp){
    bool ch= 0;
    for (int k = 0 ; k < jmp ; k ++){
        bool f = 1;
        for (int j = k ; j < 12 ; j += jmp)
            if (str[j] != 'X')
                f = 0;
        ch |= f;
    }
    if (ch)
        ans.push_back(pii(i, jmp));
}

int main(){
    int T;
    scanf("%d",&T);

    while (T --){
        ans.clear();

        scanf("%s",str);

        for (int i = 1 ; i < 4 ; i ++){
            check(i, 12/i);
            check(12/i, i);
        }

        sort(ans.begin(), ans.end());

        printf("%d",ans.size());
        for (int i = 0 ; i < (int)ans.size() ; i ++)
            printf(" %dx%d",ans[i].first,ans[i].second);
        printf("\n");
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
char str[15];

int main(){
    int T;
    scanf("%d",&T);

    while (T --){
        vector<pii> ans;

        scanf("%s",str);

        for (int i = 1 ; i < 4 ; i ++){
            int jmp = 12/i;
            bool ret = 0;
            for (int k = 0 ; k < jmp ; k ++){
                bool f = 1;
                for (int j = k ; j < 12 ; j += jmp)
                    if (str[j] != 'X')
                        f = 0;
                ret |= f;
            }
            if (ret)
                ans.push_back(pii(i, jmp));

            ret = 0;
            jmp = i;
            for (int k = 0 ; k < jmp ; k ++){
                bool f = 1;
                for (int j = k ; j < 12 ; j += jmp)
                    if (str[j] != 'X')
                        f = 0;
                ret |= f;
            }
            if (ret)
                ans.push_back(pii(12/i, jmp));
        }

        sort(ans.begin(), ans.end());

        printf("%d",ans.size());
        for (int i = 0 ; i < (int)ans.size() ; i ++)
            printf(" %dx%d",ans[i].first,ans[i].second);
        printf("\n");
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
char str[15];
vector<pii> ans;

void check(int i, int jmp){
    bool ch = 0;
    for (int k = 0 ; k < jmp ; k ++){
        bool f = 1;
        for (int j = k ; j < 12 ; j += jmp)
            if (str[j] != 'X')
                f = 0;
        ch |= f;
    }
    if (ch)
        ans.push_back(pii(i, jmp));
}

int main(){
    int T;
    scanf("%d",&T);

    while (T --){
        ans.clear();

        scanf("%s",str);

        for (int i = 1 ; i < 13 ; i ++)
            if (12 % i == 0)
                check(i, 12/i);

        printf("%d",ans.size());
        for (int i = 0 ; i < (int)ans.size() ; i ++)
            printf(" %dx%d",ans[i].first,ans[i].second);
        printf("\n");
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
char str[15];
vector<pii> ans;

void check(int i, int jmp){
    bool ch = 0;
    for (int k = 0 ; k < jmp ; k ++){
        bool f = 1;
        for (int j = k ; j < 12 ; j += jmp)
            if (str[j] != 'X')
                f = 0;
        ch |= f;
    }
    if (ch)
        ans.push_back(pii(i, jmp));
}

int main(){
    int T;
    scanf("%d",&T);

    while (T --){
        ans.clear();

        scanf("%s",str);

        for (int i = 1 ; i < 4 ; i ++)
            if (12 % i == 0)
                check(i, 12/i);

        printf("%d",ans.size());
        for (int i = 0 ; i < (int)ans.size() ; i ++)
            printf(" %dx%d",ans[i].first,ans[i].second);
        printf("\n");
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define sc scanf
#define pf printf
#define mem(a,val) memset(a,val,sizeof(a))
#define rep(s,n) for(long i=s; i<=n;i++)
#define pb push_back
#define ll long long
#define pi (2*acos(0.0))
#define mx 35000
#define ssc sscanf
#define FOR(val,n) for(long i=val;i<=n;i++)
/*bool prime[mx+5];
vector<long>v;

void sieve()
{
    for(long i=4;i<=mx; i=i+2)
    prime[i]=1;

    for(long i=3; i*i<=mx;i=i+2)
    {
        if(prime[i] == 0)
        {
            for(long j=2*i; j<=mx; j=i+j)
            prime[j]=1;
        }
    }

    v.pb(2);
    for(long i=3;i<=mx;i=i+2)
    {
        if(prime[i]==0)
        v.pb(i);
    }
}*/

struct info{

    long x,y;
};

bool com(info a,info b){

        return a.x<b.x;
}
int main()
{

    //char ch[20][20];
    string s;
    long n;
    sc("%ld",&n);

        vector<info>v;
        long cnt = 0;
        //long len;
        info temp;
        while(n--){

            v.clear();
            cnt = 0;
            cin>>s;
            //cout<<s<<endl;
            for(long j=0;j<12; j ++){
                    if(s[j] == 'X')
                    {
                        cnt++;
                        temp.x = 1;
                        temp.y = 12;
                        v.pb(temp);
                        break;
                    }

            }

            for(long j=0;j<6;j++){

                    if(s[j] == 'X' && s[j+6] == 'X'){
                          //  cout<<"here"<<endl;
                        temp.x = 2;
                        temp.y = 6;
                        cnt++;
                        v.pb(temp);
                        break;
                    }
            }

            for(long j = 0;j<4;j++){

                if(s[j] == 'X' && s[j+4]=='X' && s[j+8] =='X'){

                    cnt++;
                    temp.x = 3;
                    temp.y = 4;

                    v.pb(temp);
                    break;
                }
            }

            //for()

            for(long j=0;j<3;j++){

                if(s[j] == 'X' && s[j+3] =='X' && s[j+6] =='X' && s[j+9]){

                        temp.x=4;//cout<<"here"<<endl;
                        temp.y=3;
                        v.pb(temp);

                        cnt++;
                        break;
                }
            }
            for(long j=0;j<2;j++){

                if(s[j] == 'X' && s[j+2] == 'X' && s[j+4] == 'X' && s[j+6] == 'X' && s[j+8] =='X' && s[j+10] == 'X'){

                        temp.x = 6;
                        temp.y = 2;
                        v.pb(temp);
                        cnt++;
                        break;
                }
            }
if(s[0] == 'X'&& s[1] == 'X' && s[2] == 'X' && s[3] == 'X' && s[4] == 'X' && s[5] == 'X' && s[6] == 'X' && s[7] == 'X' && s[8] == 'X'&& s[9] == 'X' &&s[10] == 'X' &&s[11] == 'X'){

                temp.x = 12;
                temp.y = 1;
                cnt++;
                v.pb(temp);
            }

//cout<<v.size();
        cout<<cnt;
        sort(v.begin(),v.end(),com);

        for(long j=0;j<cnt;j++){
            cout<<" ";
            cout<<v[j].x<<"x"<<v[j].y;
        }cout<<endl;

v.clear();
cnt=0;
        }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define sc scanf
#define pf printf
#define mem(a,val) memset(a,val,sizeof(a))
#define rep(s,n) for(long i=s; i<=n;i++)
#define pb push_back
#define ll long long
#define pi (2*acos(0.0))
#define mx 35000
#define ssc sscanf
#define FOR(val,n) for(long i=val;i<=n;i++)
/*bool prime[mx+5];
vector<long>v;

void sieve()
{
    for(long i=4;i<=mx; i=i+2)
    prime[i]=1;

    for(long i=3; i*i<=mx;i=i+2)
    {
        if(prime[i] == 0)
        {
            for(long j=2*i; j<=mx; j=i+j)
            prime[j]=1;
        }
    }

    v.pb(2);
    for(long i=3;i<=mx;i=i+2)
    {
        if(prime[i]==0)
        v.pb(i);
    }
}*/

struct info{

    long x,y;
};

bool com(info a,info b){

        return a.x<b.x;
}
int main()
{

    char ch[20][20];
    string s;
    long n;
    sc("%ld",&n);

    vector<info>v;
        long cnt = 0;
        long len;
        info temp;
        while(n--){

            cin>>s;
            //cout<<s<<endl;
            for(long j=0;j<12; j ++){
                    if(s[j] == 'X')
                    {
                        cnt++;
                        temp.x = 1;
                        temp.y = 12;
                        v.pb(temp);
                        break;
                    }

            }

            for(long j=0;j<6;j++){

                    if(s[j] == 'X' && s[j+6] == 'X'){
                          //  cout<<"here"<<endl;
                        temp.x = 2;
                        temp.y = 6;
                        cnt++;
                        v.pb(temp);
                        break;
                    }
            }

            for(long j = 0;j<4;j++){

                if(s[j] == 'X' && s[j+4]=='X' && s[j+8] =='X'){

                    cnt++;
                    temp.x = 3;
                    temp.y = 4;

                    v.pb(temp);
                    break;
                }
            }

            //for()

            for(long j=0;j<3;j++){

                if(s[j] == 'X' && s[j+3] =='X' && s[j+6] =='X' && s[j+9]){

                        temp.x=4;//cout<<"here"<<endl;
                        temp.y=3;
                        v.pb(temp);

                        cnt++;
                        break;
                }
            }
            for(long j=0;j<2;j++){

                if(s[j] == 'X' && s[j+2] == 'X' && s[j+4] == 'X' && s[j+6] == 'X' && s[j+8] =='X' && s[j+10] == 'X'){

                        temp.x = 6;
                        temp.y = 2;
                        v.pb(temp);
                        cnt++;
                        break;
                }
            }
if(s[0] == 'X'&& s[1] == 'X' && s[2] == 'X' && s[3] == 'X' && s[4] == 'X' && s[5] == 'X' && s[6] == 'X' && s[7] == 'X' && s[8] == 'X'&& s[9] == 'X' &&s[10] == 'X' &&s[11] == 'X'){

                temp.x = 12;
                temp.y = 1;
                cnt++;
                v.pb(temp);
            }

//cout<<v.size();
        cout<<cnt;
        sort(v.begin(),v.end(),com);

        for(long j=0;j<cnt;j++){
            cout<<" ";
            cout<<v[j].x<<"x"<<v[j].y;
        }cout<<endl;

v.clear();
cnt=0;
        }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define sc scanf
#define pf printf
#define mem(a,val) memset(a,val,sizeof(a))
#define rep(s,n) for(long i=s; i<=n;i++)
#define pb push_back
#define ll long long
#define pi (2*acos(0.0))
#define mx 35000
#define ssc sscanf
#define FOR(val,n) for(long i=val;i<=n;i++)
/*bool prime[mx+5];
vector<long>v;

void sieve()
{
    for(long i=4;i<=mx; i=i+2)
    prime[i]=1;

    for(long i=3; i*i<=mx;i=i+2)
    {
        if(prime[i] == 0)
        {
            for(long j=2*i; j<=mx; j=i+j)
            prime[j]=1;
        }
    }

    v.pb(2);
    for(long i=3;i<=mx;i=i+2)
    {
        if(prime[i]==0)
        v.pb(i);
    }
}*/

struct info{

    long x,y;
};

bool com(info a,info b){

        return a.x<b.x;
}
int main()
{

    char ch[20][20];
    string s;
    long n;
    while(sc("%ld",&n) == 1){

        vector<info>v;
        long cnt = 0;
        long len;
        info temp;
        FOR(1,n){

            cin>>s;
            //cout<<s<<endl;
            for(long j=0;j<12; j ++){
                    if(s[j] == 'X')
                    {
                        cnt++;
                        temp.x = 1;
                        temp.y = 12;
                        v.pb(temp);
                        break;
                    }

            }

            for(long j=0;j<6;j++){

                    if(s[j] == 'X' && s[j+6] == 'X'){
                          //  cout<<"here"<<endl;
                        temp.x = 2;
                        temp.y = 6;
                        cnt++;
                        v.pb(temp);
                        break;
                    }
            }

            for(long j = 0;j<4;j++){

                if(s[j] == 'X' && s[j+4]=='X' && s[j+8] =='X'){

                    cnt++;
                    temp.x = 3;
                    temp.y = 4;

                    v.pb(temp);
                    break;
                }
            }

            //for()

            for(long j=0;j<3;j++){

                if(s[j] == 'X' && s[j+3] =='X' && s[j+6] =='X' && s[j+9]){

                        temp.x=4;//cout<<"here"<<endl;
                        temp.y=3;
                        v.pb(temp);

                        cnt++;
                        break;
                }
            }
            for(long j=0;j<2;j++){

                if(s[j] == 'X' && s[j+2] == 'X' && s[j+4] == 'X' && s[j+6] == 'X' && s[j+8] =='X' && s[j+10] == 'X'){

                        temp.x = 6;
                        temp.y = 2;
                        v.pb(temp);
                        cnt++;
                        break;
                }
            }
if(s[0] == 'X'&& s[1] == 'X' && s[2] == 'X' && s[3] == 'X' && s[4] == 'X' && s[5] == 'X' && s[6] == 'X' && s[7] == 'X' && s[8] == 'X'&& s[9] == 'X' &&s[10] == 'X' &&s[11] == 'X'){

                temp.x = 12;
                temp.y = 1;
                cnt++;
                v.pb(temp);
            }

//cout<<v.size();
        cout<<cnt;
        sort(v.begin(),v.end(),com);

        for(long j=0;j<v.size();j++){
            cout<<" ";
            cout<<v[j].x<<"x"<<v[j].y;
        }cout<<endl;

v.clear();
cnt=0;
        }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define sc scanf
#define pf printf
#define mem(a,val) memset(a,val,sizeof(a))
#define rep(s,n) for(long i=s; i<=n;i++)
#define pb push_back
#define ll long long
#define pi (2*acos(0.0))
#define mx 35000
#define ssc sscanf
#define FOR(val,n) for(long i=val;i<=n;i++)
/*bool prime[mx+5];
vector<long>v;

void sieve()
{
    for(long i=4;i<=mx; i=i+2)
    prime[i]=1;

    for(long i=3; i*i<=mx;i=i+2)
    {
        if(prime[i] == 0)
        {
            for(long j=2*i; j<=mx; j=i+j)
            prime[j]=1;
        }
    }

    v.pb(2);
    for(long i=3;i<=mx;i=i+2)
    {
        if(prime[i]==0)
        v.pb(i);
    }
}*/

struct info{

    long x,y;
};

bool com(info a,info b){

        if(a.x == b.x)
        return a.y<b.y;

        return a.x<b.x;
}
int main()
{

    char ch[20][20];
    string s;
    long n;
    while(sc("%ld",&n) == 1){

        vector<info>v;
        long cnt = 0;
        long len;
        info temp;
        FOR(1,n){

            cin>>s;
            //cout<<s<<endl;
            for(long j=0;j<12; j ++){
                    if(s[j] == 'X')
                    {
                        cnt++;
                        temp.x = 1;
                        temp.y = 12;
                        v.pb(temp);
                        break;
                    }

            }

            for(long j=0;j<6;j++){

                    if(s[j] == 'X' && s[j+6] == 'X'){
                          //  cout<<"here"<<endl;
                        temp.x = 2;
                        temp.y = 6;
                        cnt++;
                        v.pb(temp);
                        break;
                    }
            }

            for(long j = 0;j<4;j++){

                if(s[j] == 'X' && s[j+4]=='X' && s[j+8] =='X'){

                    cnt++;
                    temp.x = 3;
                    temp.y = 4;

                    v.pb(temp);
                    break;
                }
            }

            //for()

            for(long j=0;j<3;j++){

                if(s[j] == 'X' && s[j+3] =='X' && s[j+6] =='X' && s[j+9]){

                        temp.x=4;//cout<<"here"<<endl;
                        temp.y=3;
                        v.pb(temp);

                        cnt++;
                        break;
                }
            }
            for(long j=0;j<2;j++){

                if(s[j] == 'X' && s[j+2] == 'X' && s[j+4] == 'X' && s[j+6] == 'X' && s[j+8] =='X' && s[j+10] == 'X'){

                        temp.x = 6;
                        temp.y = 2;
                        v.pb(temp);
                        cnt++;
                        break;
                }
            }

            if(s[0] == 'X'&& s[1] == 'X' && s[2] == 'X' && s[3] == 'X' && s[4] == 'X' && s[5] == 'X' && s[6] == 'X' && s[7] == 'X' && s[8] == 'X'&& s[9] == 'X' &&s[10] == 'X' &&s[11] == 'X'){

                temp.x = 12;
                temp.y = 1;
                cnt++;
                v.pb(temp);
            }

//cout<<v.size();
        cout<<cnt<<" ";
        sort(v.begin(),v.end(),com);

        for(long j=0;j<v.size();j++){
            if(j != 0)cout<<" ";
            cout<<v[j].x<<"x"<<v[j].y;
        }cout<<endl;

v.clear();
cnt=0;
        }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define sc scanf
#define pf printf
#define mem(a,val) memset(a,val,sizeof(a))
#define rep(s,n) for(long i=s; i<=n;i++)
#define pb push_back
#define ll long long
#define pi (2*acos(0.0))
#define mx 35000
#define ssc sscanf
#define FOR(val,n) for(long i=val;i<=n;i++)
/*bool prime[mx+5];
vector<long>v;

void sieve()
{
    for(long i=4;i<=mx; i=i+2)
    prime[i]=1;

    for(long i=3; i*i<=mx;i=i+2)
    {
        if(prime[i] == 0)
        {
            for(long j=2*i; j<=mx; j=i+j)
            prime[j]=1;
        }
    }

    v.pb(2);
    for(long i=3;i<=mx;i=i+2)
    {
        if(prime[i]==0)
        v.pb(i);
    }
}*/

struct info{

    long x,y;
};

bool com(info a,info b){

        return a.x<b.x;
}
int main()
{

    char ch[20][20];
    string s;
    long n;
    while(sc("%ld",&n) == 1){

        vector<info>v;
        long cnt = 0;
        long len;
        info temp;
        FOR(1,n){

            cin>>s;
            //cout<<s<<endl;
            for(long j=0;j<12; j ++){
                    if(s[j] == 'X')
                    {
                        cnt++;
                        temp.x = 1;
                        temp.y = 12;
                        v.pb(temp);
                        break;
                    }

            }

            for(long j=0;j<6;j++){

                    if(s[j] == 'X' && s[j+6] == 'X'){
                          //  cout<<"here"<<endl;
                        temp.x = 2;
                        temp.y = 6;
                        cnt++;
                        v.pb(temp);
                        break;
                    }
            }

            for(long j = 0;j<4;j++){

                if(s[j] == 'X' && s[j+4]=='X' && s[j+8] =='X'){

                    cnt++;
                    temp.x = 3;
                    temp.y = 4;

                    v.pb(temp);
                    break;
                }
            }

            //for()

            for(long j=0;j<3;j++){

                if(s[j] == 'X' && s[j+3] =='X' && s[j+6] =='X' && s[j+9]){

                        temp.x=4;//cout<<"here"<<endl;
                        temp.y=3;
                        v.pb(temp);

                        cnt++;
                        break;
                }
            }
            for(long j=0;j<2;j++){

                if(s[j] == 'X' && s[j+2] == 'X' && s[j+4] == 'X' && s[j+6] == 'X' && s[j+8] =='X' && s[j+10] == 'X'){

                        temp.x = 6;
                        temp.y = 2;
                        v.pb(temp);
                        cnt++;
                        break;
                }
            }
if(s[0] == 'X'&& s[1] == 'X' && s[2] == 'X' && s[3] == 'X' && s[4] == 'X' && s[5] == 'X' && s[6] == 'X' && s[7] == 'X' && s[8] == 'X'&& s[9] == 'X' &&s[10] == 'X' &&s[11] == 'X'){

                temp.x = 12;
                temp.y = 1;
                cnt++;
                v.pb(temp);
            }

//cout<<v.size();
        cout<<cnt<<" ";
        sort(v.begin(),v.end(),com);

        for(long j=0;j<v.size();j++){
            if(j != 0)cout<<" ";
            cout<<v[j].x<<"x"<<v[j].y;
        }cout<<endl;

v.clear();
cnt=0;
        }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define sc scanf
#define pf printf
#define pb push_back

#define Abs(n) (n<0?-n:n)
#define Mem(a,b) memset(a,b,sizeof(a))
#define Memcpy(a,b) memcopy(a,b,sizeof(a))
#define eps 1e-9
#define Pi 2*acos(0.0)
#define INF 0x7f7f7f7f
#define sq(x) x*x

#define Read(f)freopen(f,"r",stdin);
#define Write(f)freopen(f,"w",stdout);

#define mx 1000000

long dx[]= {-1, -1, -1,  0, 0,  1, 1, 1};
long dy[]= {-1,  0,  1, -1, 1, -1, 0, 1};

bool prime[mx+2];
vector <long long> primes;

void seive()
{
    for(long long i=4; i<=mx; i+=2)
        prime[i]=1;

    for(long long i=3; i*i<=mx; i+=2)
    {
        if(prime[i]==0)
        {
            for(long long j=2*i; j<=mx; j+=i)
                prime[j]=1;
        }
    }

    primes.pb(2);
    for(long long i=3; i<=mx; i+=2)
        if(prime[i]==0)
            primes.pb(i);
}

long long gcd(long long a, long long b)
{
    return __gcd(a, b);
}

long long lcm(long long a, long long b)
{
    long gcD = gcd(a,b);
    long lcM = (a*b)/gcD;

    return lcM;
}

long long bigMod(long long b, long long p, long long m)
{
    if(p==0)
        return 1;
    else if( p&1 )
        return ((b%m)*bigMod(b, p-1, m))%m;
    else
        return sq(bigMod(b, p>>1, m))%m;
}

long long modInverse(long long b, long long m)
{
    return bigMod(b, m-2, m);
}

long long fastExpo(long long b, long long p)
{
    long long res=1, x=b;
    while(p)
    {
        if(p&1) res*=x;
        x*=x;
        p=p>>1;
    }
    return p;
}

bool stringMod(string a, long long n)
{
    long long num=0;
    for(long i=0; i<a.size(); i++)
        num=((num*10) + (a[i]-'0'))%n;

    if(num==0)
        return 1;
    else
        return 0;
}

int main()
{
    long T, ans;
    char ch[13];
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>T;
    while(T--)
    {
        cin>>ch;

        long nx=0;
        for(long i=0; i<12; i++)
            if(ch[i] == 'X')
                nx++;
        long ans=0;

        if(nx>0) ans++;

        long two=0, three=0, four=0, six=0, twelve=0;

        for(long i=0; i<6; i++)
            if(ch[i] == 'X' && ch[i+6] == 'X')
            {
                ans++;
                two = 1;
                break;
            }

        for(long i=0; i<4; i++)
            if(ch[i] == 'X' && ch[i+4] == 'X' && ch[i+8] == 'X')
            {
                ans++;
                three = 1;
                break;
            }

        for(long i=0; i<3; i++)
            if(ch[i] == 'X' && ch[i+3] == 'X' && ch[i+6]=='X' && ch[i+9] == 'X')
            {
                ans++;
                four = 1;
                break;
            }

        for(long i=0; i<2; i++)
            if(ch[i] == 'X' && ch[i+2] == 'X' && ch[i+4] == 'X' && ch[i+6] == 'X' && ch[i+8] == 'X' && ch[i+10] == 'X')
            {
                ans++;
                six = 1;
                break;
            }

        if(nx == 12)
        {
            ans++;
            twelve=1;
        }

        cout<<ans;

        if(nx > 0)
            cout<<" 1x12";

        if(two == 1)
            cout<<" 2x6";
        if(three == 1)
            cout<<" 3x4";
        if(four == 1)
            cout<<" 4x3";
        if(six == 1)
            cout<<" 6x2";
        if(twelve == 1)
            cout<<" 12x1";
        cout<<endl;

    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#pragma comment(linker, "/STACK:640000000")
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
using namespace std;
typedef pair<int, int> pii;
const double eps = 1e-9;
const double pi = acos(-1.0);
int main() {
    #ifndef HOME
    freopen("in.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int T; cin >> T;
    while(T--) {
        string s; cin >> s;
        vector<int> v;
        for (int i = 1; i <= 12; i++) if (12 % i == 0) {
            bool yes = false;
            int a = i;
            int b = 12 / i;
            for (int j = 0; j < b; j++) {
                bool ok = true;
                for (int k = 0; k < a; k++) {
                    ok &= s[k * b + j] == 'X';
                }
                if (ok) yes = true;
            }
            if (yes) v.pb(i);
        }
        cout << sz(v);
        for (int i = 0; i < sz(v); i++) {
            cout << " ";
            cout << v[i] << "x" << 12 / v[i];
        }
        cout << endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#pragma comment(linker, "/STACK:640000000")
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
using namespace std;
typedef pair<int, int> pii;
const double eps = 1e-9;
const double pi = acos(-1.0);
int main() {
    #ifndef ONLINE_JUGDE
    freopen("in.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int T; cin >> T;
    while(T--) {
        string s; cin >> s;
        vector<int> v;
        for (int i = 1; i <= 12; i++) if (12 % i == 0) {
            bool yes = false;
            int a = i;
            int b = 12 / i;
            for (int j = 0; j < b; j++) {
                bool ok = true;
                for (int k = 0; k < a; k++) {
                    ok &= s[k * b + j] == 'X';
                }
                if (ok) yes = true;
            }
            if (yes) v.pb(i);
        }
        cout << sz(v);
        for (int i = 0; i < sz(v); i++) {
            cout << " ";
            cout << v[i] << "x" << 12 / v[i];
        }
        cout << endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#pragma comment(linker, "/STACK:640000000")
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
using namespace std;
typedef pair<int, int> pii;
const double eps = 1e-9;
const double pi = acos(-1.0);
int main() {
    #ifndef ONLINE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t; cin >> t;
    while(t--) {
        string s; cin >> s;
        vector<int> v;
        for (int i = 1; i <= 12; i++) if (12 % i == 0) {
            bool yes = false;
            int a = i;
            int b = 12 / i;
            for (int j = 0; j < b; j++) {
                bool ok = true;
                for (int k = 0; k < a; k++) {
                    ok &= s[k * b + j] == 'X';
                }
                if (ok) yes = true;
            }
            if (yes) v.pb(i);
        }
        cout << sz(v);
        for (int i = 0; i < sz(v); i++) {
            cout << " ";
            cout << v[i] << "x" << 12 / v[i];
        }
        cout << endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#pragma comment(linker, "/STACK:640000000")
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
using namespace std;
typedef pair<int, int> pii;
const double eps = 1e-9;
const double pi = acos(-1.0);
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t; cin >> t;
    while(t--) {
        string s; cin >> s;
        vector<int> v;
        for (int i = 1; i <= 12; i++) if (12 % i == 0) {
            bool yes = false;
            int a = i;
            int b = 12 / i;
            for (int j = 0; j < b; j++) {
                bool ok = true;
                for (int k = 0; k < a; k++) {
                    ok &= s[k * b + j] == 'X';
                }
                if (ok) yes = true;
            }
            if (yes) v.pb(i);
        }
        cout << sz(v);
        for (int i = 0; i < sz(v); i++) {
            cout << " ";
            cout << v[i] << "x" << 12 / v[i];
        }
        cout << endl;
    }
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t; cin>>t;
    while(t--){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        int x; cin>>x;
        a[x-1]=i;
    }
    int prev=-1,ans=0;
    for(int i=0;i<m;i++){
        int b;cin>>b;
        int pos= a[b];
        if(pos<prev) ans++;
        else{
            ans+=2*pos+1;
            prev=i;
        }
    }
    cout<<ans<<"\n";
    }
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t; cin>>t;
    while(t--){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        int x; cin>>x;
        a[x-1]=i;
    }
    long long prev=-1,ans=0;
    for(int i=0;i<m;i++){
        int b;cin>>b;
        int pos= a[b-1];
        if(pos<prev) ans++;
        else{
            ans+=2*(pos-i)+1;
            prev=pos;
        }
    }
    cout<<ans<<"\n";
    }
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t; cin>>t;
    while(t--){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        int x; cin>>x;
        a[x-1]=i;
    }
    int prev=-1,ans=0;
    for(int i=0;i<m;i++){
        int b;cin>>b;
        int pos= a[b-1];
        if(pos<prev) ans++;
        else{
            ans+=2*pos+1;
            prev=i;
        }
    }
    cout<<ans<<"\n";
    }
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t; cin>>t;
    while(t--){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        int x; cin>>x;
        a[x-1]=i;
    }
    int prev=-1,ans=0;
    for(int i=0;i<m;i++){
        int b;cin>>b;
        int pos= a[b-1];
        if(pos<prev) ans++;
        else{
            ans+=2*pos+1;
            prev=pos;
        }
    }
    cout<<ans<<"\n";
    }
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t; cin>>t;
    while(t--){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        int x; cin>>x
        a[x-1]=i;
    }
    int prev=-1;
    for(int i=0;i<m;i++){
        int b;cin>>b;
        int pos= a[b];
        if(pos<prev) ans++;
        else{
            and+=2*pos+1;
            prev=i;
        }
    }
    count<<ans<<"\n";
    }
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t; cin>>t;
    while(t--){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        int x; cin>>x
        a[x-1]=i;
    }
    int prev=-1,ans=0;
    for(int i=0;i<m;i++){
        int b;cin>>b;
        int pos= a[b];
        if(pos<prev) ans++;
        else{
            and+=2*pos+1;
            prev=i;
        }
    }
    count<<ans<<"\n";
    }
}


#include<iostream>
using namespace std;

int main(){
    int t; cin>>t;
    while(t--){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        int x; cin>>x
        a[x-1]=i;
    }
    int prev=-1;
    for(int i=0;i<m;i++){
        int b;cin>>b;
        int pos= a[b];
        if(pos<prev) ans++;
        else{
            and+=2*pos+1;
            prev=i;
        }
    }
    count<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
#define      pb    push_back
#define      loop(i,a,b) for(int i=a;i<=b;i++)
#define      sd(x)   scanf("%d", &x)
#define      sdd(x)  scanf("%lld", &x)
#define      pd(x)   printf("%d\n", x)
#define      pdd(x)  printf("%lld\n", x)
#define      all(x)  x.begin(), x.end()
#define      mod     (int)(1e9+7)
#define      pi      pair<int,int>
#define      vi      vector<int>
#define      done    std::ios::sync_with_stdio(false);  cin.tie(NULL);
typedef long long ll;
using namespace std;
int a[100005],b[100005],indb[100005],vis[100005];
void solve()
{
	int n,m;
	cin>>n>>m;
	loop(i,1,n){
		cin>>a[i];
		vis[a[i]]=0;
		indb[a[i]]=0;
	}
	loop(i,1,m){
		cin>>b[i];
		indb[b[i]]=i;
	}
	int cur=0,ans=0,ind=1,fl=0;
	for(int i=1;i<=n;i++){
		if(indb[a[i]]){
			if(indb[a[i]]==ind){
				ans+=2*cur+1;
				cur--;
				ind++;
				cur=max(0,cur);
				fl++;
			}
			else{
				if(vis[ind]) ans++,cur--,cur=max(0,cur),fl++;
				else vis[indb[a[i]]]=1,cur++;
			}
		}
		else cur++;
	}
	if(fl<m) ans+=(m-fl);
	cout<<ans<<endl;
}
int main()
{
	done
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>
#define      pb    push_back
#define      loop(i,a,b) for(int i=a;i<=b;i++)
#define      sd(x)   scanf("%d", &x)
#define      sdd(x)  scanf("%lld", &x)
#define      pd(x)   printf("%d\n", x)
#define      pdd(x)  printf("%lld\n", x)
#define      all(x)  x.begin(), x.end()
#define      mod     (int)(1e9+7)
#define      pi      pair<int,int>
#define      vi      vector<int>
#define      done    std::ios::sync_with_stdio(false);  cin.tie(NULL);
typedef long long ll;
using namespace std;
int a[100005],b[100005],indb[100005],vis[100005];
void solve()
{
	int n,m;
	cin>>n>>m;
	loop(i,1,n){
		cin>>a[i];
		vis[i]=0;
		indb[i]=0;
	}
	loop(i,1,m){
		cin>>b[i];
		indb[b[i]]=i;
	}
	ll cur=0,ans=0,ind=1,fl=0;
	for(int i=1;i<=n;i++){
	    while(ind<=m&&vis[ind]) ind++,ans++,cur--;
		if(indb[a[i]]){
			if(indb[a[i]]==ind){
				ans+=(2*cur+1);
				ind++;
			}
			else{
				vis[indb[a[i]]]=1,cur++;
			}
		}
		else cur++;
	}
	if(ind<=m) ans+=(m-ind+1);
	cout<<ans<<endl;
}
int main()
{
	done
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>
#define      pb    push_back
#define      loop(i,a,b) for(int i=a;i<=b;i++)
#define      sd(x)   scanf("%d", &x)
#define      sdd(x)  scanf("%lld", &x)
#define      pd(x)   printf("%d\n", x)
#define      pdd(x)  printf("%lld\n", x)
#define      all(x)  x.begin(), x.end()
#define      mod     (int)(1e9+7)
#define      pi      pair<int,int>
#define      vi      vector<int>
#define      done    std::ios::sync_with_stdio(false);  cin.tie(NULL);
typedef long long ll;
using namespace std;
int a[100005],b[100005],indb[100005],vis[100005];
void solve()
{
	int n,m;
	cin>>n>>m;
	loop(i,1,n){
		cin>>a[i];
		vis[a[i]]=0;
		indb[a[i]]=0;
	}
	loop(i,1,m){
		cin>>b[i];
		indb[b[i]]=i;
	}
	int cur=0,ans=0,ind=1,fl=0;
	for(int i=1;i<=n;i++){
		if(indb[a[i]]){
			if(indb[a[i]]==ind){
				ans+=2*cur+1;
				ind++;
			}
			else{
				if(vis[ind]) ans++,cur--,ind++;
				else vis[indb[a[i]]]=1,cur++;
			}
		}
		else cur++;
	}
	if(ind<=m) ans+=(m-ind+1);
	cout<<ans<<endl;
}
int main()
{
	done
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>
#define      pb    push_back
#define      loop(i,a,b) for(int i=a;i<=b;i++)
#define      sd(x)   scanf("%d", &x)
#define      sdd(x)  scanf("%lld", &x)
#define      pd(x)   printf("%d\n", x)
#define      pdd(x)  printf("%lld\n", x)
#define      all(x)  x.begin(), x.end()
#define      mod     (int)(1e9+7)
#define      pi      pair<int,int>
#define      vi      vector<int>
#define      done    std::ios::sync_with_stdio(false);  cin.tie(NULL);
typedef long long ll;
using namespace std;
int a[100005],b[100005],indb[100005],vis[100005];
void solve()
{
	int n,m;
	cin>>n>>m;
	loop(i,1,n){
		cin>>a[i];
		vis[a[i]]=0;
		indb[a[i]]=0;
	}
	loop(i,1,m){
		cin>>b[i];
		indb[b[i]]=i;
	}
	int cur=0,ans=0,ind=1,fl=0;
	for(int i=1;i<=n;i++){
		if(indb[a[i]]){
			if(indb[a[i]]==ind){
				ans+=2*cur+1;
				ind++;
				fl++;
			}
			else{
				if(vis[ind]) ans++,cur--,cur=max(0,cur),fl++;
				else vis[indb[a[i]]]=1,cur++;
			}
		}
		else cur++;
	}
	if(fl<m) ans+=(m-fl);
	cout<<ans<<endl;
}
int main()
{
	done
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>
#define      pb    push_back
#define      loop(i,a,b) for(int i=a;i<=b;i++)
#define      sd(x)   scanf("%d", &x)
#define      sdd(x)  scanf("%lld", &x)
#define      pd(x)   printf("%d\n", x)
#define      pdd(x)  printf("%lld\n", x)
#define      all(x)  x.begin(), x.end()
#define      mod     (int)(1e9+7)
#define      pi      pair<int,int>
#define      vi      vector<int>
#define      done    std::ios::sync_with_stdio(false);  cin.tie(NULL);
typedef long long ll;
using namespace std;
int a[100005],b[100005],indb[100005],vis[100005];
void solve()
{
	int n,m;
	cin>>n>>m;
	loop(i,1,n){
		cin>>a[i];
		vis[a[i]]=0;
		indb[a[i]]=0;
	}
	loop(i,1,m){
		cin>>b[i];
		indb[b[i]]=i;
	}
	int cur=0,ans=0,ind=1,fl=0;
	for(int i=1;i<=n;i++){
		if(indb[a[i]]){
			if(indb[a[i]]==ind){
				ans+=(2*cur+1);
				ind++;
			}
			else{
				if(vis[ind]) ans++,cur--,ind++;
				else vis[indb[a[i]]]=1,cur++;
			}
		}
		else cur++;
	}
	if(ind<=m) ans+=(m-ind+1);
	cout<<ans<<endl;
}
int main()
{
	done
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>
#define      pb    push_back
#define      loop(i,a,b) for(int i=a;i<=b;i++)
#define      sd(x)   scanf("%d", &x)
#define      sdd(x)  scanf("%lld", &x)
#define      pd(x)   printf("%d\n", x)
#define      pdd(x)  printf("%lld\n", x)
#define      all(x)  x.begin(), x.end()
#define      mod     (int)(1e9+7)
#define      pi      pair<int,int>
#define      vi      vector<int>
#define      done    std::ios::sync_with_stdio(false);  cin.tie(NULL);
typedef long long ll;
using namespace std;
int a[100005],b[100005],indb[100005],vis[100005];
void solve()
{
	int n,m;
	cin>>n>>m;
	loop(i,1,n){
		cin>>a[i];
		vis[a[i]]=0;
		indb[a[i]]=0;
	}
	loop(i,1,m){
		cin>>b[i];
		indb[b[i]]=i;
	}
	int cur=0,ans=0,ind=1,fl=0;
	for(int i=1;i<=n;i++){
		if(indb[a[i]]){
			if(indb[a[i]]==ind){
				ans+=2*cur+1;
				ind++;
				fl++;
			}
			else{
				if(vis[ind]) ans++,cur--,cur=max(0,cur),fl++,ind++;
				else vis[indb[a[i]]]=1,cur++;
			}
		}
		else cur++;
	}
	if(fl<m) ans+=(m-fl);
	cout<<ans<<endl;
}
int main()
{
	done
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>
#define      pb    push_back
#define      loop(i,a,b) for(int i=a;i<=b;i++)
#define      sd(x)   scanf("%d", &x)
#define      sdd(x)  scanf("%lld", &x)
#define      pd(x)   printf("%d\n", x)
#define      pdd(x)  printf("%lld\n", x)
#define      all(x)  x.begin(), x.end()
#define      mod     (int)(1e9+7)
#define      pi      pair<int,int>
#define      vi      vector<int>
#define      done    std::ios::sync_with_stdio(false);  cin.tie(NULL);
typedef long long ll;
using namespace std;
int a[100005],b[100005],inda[100005],indb[100005],vis[100005];
void solve()
{
	int n,m;
	cin>>n>>m;
	loop(i,1,n){
		cin>>a[i];
		inda[a[i]]=1;
		vis[a[i]]=0;
	}
	loop(i,1,m){
		cin>>b[i];
		indb[b[i]]=i;
	}
	int cur=0,ans=0,ind=1,fl=0;
	for(int i=1;i<=n;i++){
		if(indb[a[i]]){
			if(indb[a[i]]==ind){
				ans+=2*cur+1;
				cur--;
				ind++;
				cur=max(0,cur);
				fl++;
			}
			else{
				if(vis[ind]) ans++,cur--,cur=max(0,cur),fl++;
				else vis[indb[a[i]]]=1,cur++;
			}
		}
		else cur++;
	}
	if(fl<m) ans+=(m-fl);
	cout<<ans<<endl;
}
int main()
{
	done
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>
#define      pb    push_back
#define      loop(i,a,b) for(int i=a;i<=b;i++)
#define      sd(x)   scanf("%d", &x)
#define      sdd(x)  scanf("%lld", &x)
#define      pd(x)   printf("%d\n", x)
#define      pdd(x)  printf("%lld\n", x)
#define      all(x)  x.begin(), x.end()
#define      mod     (int)(1e9+7)
#define      pi      pair<int,int>
#define      vi      vector<int>
#define      done    std::ios::sync_with_stdio(false);  cin.tie(NULL);
typedef long long ll;
using namespace std;
int a[100005],b[100005],indb[100005],vis[100005];
void solve()
{
	int n,m;
	cin>>n>>m;
	loop(i,1,n){
		cin>>a[i];
		vis[i]=0;
		indb[i]=0;
	}
	loop(i,1,m){
		cin>>b[i];
		indb[b[i]]=i;
	}
	ll cur=0,ans=0,ind=1,fl=0;
	for(int i=1;i<=n;i++){
		if(indb[a[i]]){
			if(indb[a[i]]==ind){
				ans+=(1ll*2*cur+1);
				ind++;
			}
			else{
				if(vis[ind]) ans++,cur--,ind++;
				else vis[indb[a[i]]]=1,cur++;
			}
		}
		else cur++;
	}
	if(ind<=m) ans+=1ll*(m-ind+1);
	cout<<ans<<endl;
}
int main()
{
	done
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order[j]=1000000000;
        vector<int> a(n), b(n1);
        for(int j = 0; j < n; j++)
            cin >> a[j];
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
            order[b[j]]=j;
        }
        int sum=0;
        for(int j = 0; j < n1; j++)
        {
            bool found=false;
            int useless=0;
            for(int k = 0; k < a.size() && !found; k++)
            {
                if(a[k]==b[j])
                {
                    found=true;
                    a.erase(a.begin()+k);
                    sum=sum+2*(k-useless)+1;
                }
                else
                {
                    int l=k;
                    while(l > 0 && order[a[l]] < order[a[l-1]])
                    {
                        swap(a[l], a[l-1]);
                        l--;
                    }
                }
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int p=1;
        while(p <= n)
            p*=2;
        int order_tree[2*p+1];
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order_tree[j]=0;
        vector<int> a(n), b(n1);
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        long long int sum=0, ma=0;
        for(int j = 0; j < n1; j++)
        {
            int m=order[b[j]];
            if(order[b[j]] < ma)
                sum++;
            else
            {
                ma = order[b[j]];
                int x, y;
                x=p+order[b[j]]+1;
                y=2*p+1;
                while(x <= y)
                {
                    if(x%2==1)
                    {
                        order_tree[x]++;
                        x++;
                    }
                    if(y%2==0)
                    {
                        order_tree[y]++;
                        y--;
                    }
                    x/=2;
                    y/=2;
                }
                x=(p+order[b[j]])/2;
                while(x >= 1)
                {
                    m-=order_tree[x];
                    x/=2;
                }
                sum=sum+2*m+1;
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int p=1;
        while(p <= n)
            p*=2;
        int order_tree[2*p+1];
        int order[n+1];
        for(int j = 0; j < 2*p+1; j++)
            order_tree[j]=0;
        vector<int> a(n), b(n1);
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        long long int sum=0, ma=0;
        for(int j = 0; j < n1; j++)
        {
            int m=order[b[j]];
            if(order[b[j]] < ma)
                sum++;
            else
            {
                ma = order[b[j]];
                int x, y;
                x=p+order[b[j]]+1;
                y=2*p+1;
                while(x <= y)
                {
                    if(x%2==1)
                    {
                        order_tree[x]++;
                        x++;
                    }
                    if(y%2==0)
                    {
                        order_tree[y]++;
                        y--;
                    }
                    x/=2;
                    y/=2;
                }
                x=(p+order[b[j]])/2;
                while(x >= 1)
                {
                    m-=order_tree[x];
                    x/=2;
                }
                sum=sum+2*m+1;
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order[j]=1000000000;
        int a[n], b[n1];
        for(int j = 0; j < n; j++)
            cin >> a[j];
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
            order[b[j]]=j;
        }
        int sum=0;
        for(int j = 0; j < n1; j++)
        {
            bool found=false;
            int useless=0;
            for(int k = 0; k < n && !found; k++)
            {
                if(a[k]==-1)
                    useless++;
                else if(a[k]==b[j])
                {
                    found=true;
                    a[k]=-1;
                    sum=sum+2*(k-useless)+1;
                }
                else
                {
                    int l=k;
                    while(l > 0 && order[a[l]] < order[a[l-1]])
                    {
                        swap(a[l], a[l-1]);
                        l--;
                    }
                }
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int p=1;
        while(p <= n)
            p*=2;
        int order_tree[2*p+1];
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order_tree[j]=0;
        vector<int> a(n), b(n1);
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        int sum=0, ma=0;
        for(int j = 0; j < n1; j++)
        {
            int x, y;
            x=p+order[b[j]]+1;
            y=2*p+1;
            while(x <= y)
            {
                if(x%2==1)
                {
                    order_tree[x]++;
                    x++;
                }
                if(y%2==0)
                {
                    order_tree[y]++;
                    y--;
                }
                x/=2;
                y/=2;
            }
            int m=order[b[j]];
            if(order[b[j]] < ma)
                sum++;
            else
            {
                ma=max(ma, order[b[j]]);
                x=(p+order[b[j]])/2;
                while(x >= 1)
                {
                    m-=order_tree[x];
                    x/=2;
                }
                sum=sum+2*m+1;
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int p=1;
        while(p <= n+1)
            p*=2;
        long long int order_tree[2*p+1];
        int order[n+1];
        for(int j = 0; j < 2*p+1; j++)
            order_tree[j]=0;
        vector<int> a(n), b(n1);
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        long long int sum=0, ma=0;
        for(int j = 0; j < n1; j++)
        {
            int m=order[b[j]];
            if(order[b[j]] < ma)
                sum++;
            else
            {
                ma = order[b[j]];
                int x, y;
                x=p+order[b[j]]+1;
                y=2*p+1;
                while(x <= y)
                {
                    if(x%2==1)
                    {
                        order_tree[x]++;
                        x++;
                    }
                    if(y%2==0)
                    {
                        order_tree[y]++;
                        y--;
                    }
                    x/=2;
                    y/=2;
                }
                x=(p+order[b[j]])/2;
                while(x >= 1)
                {
                    m-=order_tree[x];
                    x/=2;
                }
                sum=sum+2*m+1;
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int p=1;
        while(p <= n)
            p*=2;
        int order_tree[2*p+1];
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order_tree[j]=0;
        vector<int> a(n), b(n1);
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        int sum=0, ma=0;
        for(int j = 0; j < n1; j++)
        {
            int m=order[b[j]];
            if(order[b[j]] < ma)
                sum++;
            else
            {
                ma=max(ma, order[b[j]]);
                int x, y;
            x=p+order[b[j]]+1;
            y=2*p+1;
            while(x <= y)
            {
                if(x%2==1)
                {
                    order_tree[x]++;
                    x++;
                }
                if(y%2==0)
                {
                    order_tree[y]++;
                    y--;
                }
                x/=2;
                y/=2;
            }
                x=(p+order[b[j]])/2;
                while(x >= 1)
                {
                    m-=order_tree[x];
                    x/=2;
                }
                sum=sum+2*m+1;
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int p=1;
        while(p <= n+1)
            p*=2;
        long long int order_tree[2*p+1];
        int order[n+1];
        for(int j = 0; j < 2*p+1; j++)
            order_tree[j]=0;
        int a[n], b[n1];
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        long long int sum=0, ma=0;
        for(int j = 0; j < n1; j++)
        {
            int m=order[b[j]];
            int x, y;
            if(order[b[j]] < ma)
                sum++;
            else
            {
                ma = order[b[j]];

                x=(p+order[b[j]])/2;
                while(x >= 1)
                {
                    m-=order_tree[x];
                    x/=2;
                }
                sum=sum+2*m+1;
            }
            x=p+order[b[j]];
                y=2*p;
                while(x <= y)
                {
                    if(x%2==1)
                    {
                        order_tree[x]++;
                        x++;
                    }
                    if(y%2==0)
                    {
                        order_tree[y]++;
                        y--;
                    }
                    x/=2;
                    y/=2;
                }
        }
        cout << sum << '\n';
    }
}