#include "stdio.h"
#include "string.h"
int main()
{
char a[1010],b[1010]; //a为子串,b为母串
int N;
scanf("%d",&N);
while(N)
{
scanf("%s%s",a,b);
int x,y,count=0;
int j=0;
x=strlen(a);
y=strlen(b);
for(int i=0;i<x;i++)
for(;j<y;j++)
if(a[i]==b[j])
{
count++;
break;
}
printf("%d\n",count);
}
return 0;
}