#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); i++)
#define ll long long
using namespace std;

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

