#include <bits/stdc++.h>

using namespace std;

signed main() {
  int n; cin >> n;
  string x,y;
  while(n--){
    cin >> x >> y;
    vector<vector<int> > dp(x.size()+1,vector<int>(y.size()+1));
    for(int i=0;i<x.size();++i){
      for(int j=0;j<y.size();++j){
	if(x[i]==y[j]) dp[i+1][j+1]=dp[i][j]+1;
	else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
    cout << dp[x.size()][y.size()] << endl;
  }
  
  return 0;
}
