#include<stdio.h>
#include<string.h>
#define N 1000
int longco(char X[],char Y[])
{
  int A[N+1][N+1];
  int i,j;
  int m=strlen(X);
  int n=strlen(Y);
  int max=0;
  for(i=1;i<=m;i++)A[i][0]=0;
  for(j=1;j<=n;j++)A[0][j]=0;
  
  for(i=1;i<=m;i++)
    {
      for(j=1;j<=n;j++)
	{
	  if(X[i-1]==Y[j-1]) A[i][j]=A[i-1][j-1]+1;
	  else
	    {
	      if(A[i-1][j]>A[i][j-1])A[i][j]=A[i-1][j];
	      else if(A[i-1][j]<A[i][j-1])A[i][j]=A[i][j-1];
	    }
	  if(max>A[i][j])max=max;
	  else if(max<A[i][j])max=A[i][j];
	}
    }
  return max;
}

int main()
{
  char s1[N],s2[N];
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s %s",s1,s2);
      printf("%d\n",longco(s1,s2));
    }
  return 0;
}
  