#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int q;
  cin >> q;
  string x, y;
  rep(_, q){
    cin >> x >> y;
    int n = x.size();
    int m = y.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    rep(i, n)rep(j, m){
      if (x[i] == y[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
    }
    cout << dp[n][m] << endl;
  }
  
  return 0;
}
