#include <stdio.h>
#include<stdlib.h>

    int penalty_shoot(char* s){
        int count=0,i=0;
        while(s[i]!='\0'){
           if(s[i]=='2')
                if(s[i+1]=='1')
                    count++;
        i++;
        }
        return count;
    }

    int main() {
        int t;
        int i=0;
        scanf("%d ",&t);           //t is for number of test cases.
        while(t--){
            char *str, c;
            str = (char*)malloc(1*sizeof(char));
            while(c = getc(stdin),c!='\n'&&c!=EOF)
            {
                str[i] = c;
                i++;
                str=realloc(str,(i+1)*sizeof(char));
            }
            str[i] ='\0';
            printf("%s\n",str);
            printf("%d\n",penalty_shoot(str));

            free(str);
            str=NULL;
            i=0;
        }
        return 0;
    }