#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int MAX_L = 10000;
int q;

string data[MAX_N][2];
ll mem[MAX_L][MAX_L];

ll eval(string s1, string s2, int i, int j) {
  int ii = i - 1;
  int jj = j - 1;
  if (ii == -1 || jj == -1)
    return 0;
  if (s1[ii] == s2[jj])
    return mem[i - 1][j - 1] + 1;
  if (s1[ii] != s2[jj])
    return max(mem[i - 1][j], mem[i][j - 1]);
  throw "exception";
}

ll solve(string s1, string s2) {

  int L1 = s1.size();
  int L2 = s2.size();
  rep(i, L1 + 1) {
    rep(j, L2 + 1) { mem[i][j] = eval(s1, s2, i, j); }
  }

  return mem[L1][L2];
}

int main() {

  cin >> q;
  rep(i, q) {
    cin >> data[i][0];
    cin >> data[i][1];
  }

  rep(i, q) { cout << solve(data[i][0], data[i][1]) << endl; }
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int MAX_L = 10000;
int q;

string data[MAX_N][2];
ll mem[MAX_L][MAX_L];

ll eval(string &s1, string &s2, int i, int j) {
  int ii = i - 1;
  int jj = j - 1;
  if (ii == -1 || jj == -1)
    return 0;
  if (s1[ii] == s2[jj])
    return mem[i - 1][j - 1] + 1;
  if (s1[ii] != s2[jj])
    return max(mem[i - 1][j], mem[i][j - 1]);
  throw "exception";
}

ll solve(string s1, string s2) {

  int L1 = s1.size();
  int L2 = s2.size();
  rep(i, L1 + 1) {
    rep(j, L2 + 1) { mem[i][j] = eval(s1, s2, i, j); }
  }

  return mem[L1][L2];
}

int main() {

  cin >> q;
  rep(i, q) {
    cin >> data[i][0];
    cin >> data[i][1];
  }

  rep(i, q) { cout << solve(data[i][0], data[i][1]) << endl; }
}


#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <inttypes.h>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

int LCS(std::string s, std::string t) {
  int n, m, c[n + 1][m + 1];
  n = s.size();
  m = t.size();
  int maxlen = 0;
  for (int i = 0; i <= n; i++) {
    c[i][0] = 0;
  }
  for (int i = 0; i <= m; i++) {
    c[0][i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[i]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
      }
      maxlen = std::max(c[i][j], maxlen);
    }
  }
  return maxlen;
}
int main() {
  int N;

  std::cin >> N;
  std::string s1, s2;
  for (int i = 0; i < N; i++) {
    std::cin >> s1 >> s2;
    std::cout << LCS(s1, s2) << std::endl;
  }

  return 0;
}

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <inttypes.h>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

int LCS(std::string s, std::string t) {
  int n, m, c[1001][1001] = {0};
  n = s.size();
  m = t.size();
  int maxlen = 0;
  for (int i = 1; i <= n; i++) {
    c[i][0] = 0;
  }
  for (int i = 1; i <= m; i++) {
    c[0][i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
      }
      maxlen = std::max(maxlen, c[i][j]);
    }
  }
  return maxlen;
}
int main() {
  int N;

  std::cin >> N;
  std::string s1, s2;
  for (int i = 0; i < N; i++) {
    std::cin >> s1 >> s2;
    std::cout << LCS(s1, s2) << std::endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if __has_include("print.hpp")
#include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

int n, w;
vector<vector<int>> dp(10000, vector<int>(10000, -1));
vector<int> vv;
vector<int> wv;

void solve() {
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < w; j++) {
      if (j < wv[i]) {
        dp[i][j] = dp[i + 1][j];
      } else {
        dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - wv[i]] + vv[i]);
      }
    }
  }
}

int main() {
  cin >> n >> w;
  for (int i = 0; i < n; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    wv.push_back(tmp1);
    vv.push_back(tmp2);
  }

  solve();
  cout << dp[0][w] << endl;
}

#include <bits/stdc++.h>
using namespace std;

#if __has_include("print.hpp")
#include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

vector<vector<int>> dp(2000, vector<int>(2000));

void solve(string s, string t) {
  int n = int(s.size());
  int m = int(t.size());

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
      }
    }
  }

  cout << dp[n][m] << endl;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s, t;
    cin >> s >> t;
    solve(s, t);
  }
}


#include <iostream>
#include <string>
int main() {
  int n;
  int an[1000];
  int l = 0;
  std::cin >> n;
  std::string x;
  std::string y;
  int ans[10000][10000];
  int j, k;
  for (int i = 0; i < n; i++) {
    std::cin >> x;
    std::cin >> y;
    for (int j = 0; j < 10000; j++) {
      for (int k = 0; k < 10000; k++) {
        ans[j][k] = 0;
      }
    }
    for (int j = 0; j < x.size(); j++) {
      for (int k = 0; k < y.size(); k++) {
        if (x[j] == y[k]) {
          ans[j][k] = ans[j - 1][k - 1] + 1;
        } else {
          if (ans[j][k - 1] > ans[j - 1][k]) {
            ans[j][k] = ans[j][k - 1];
          } else {
            ans[j][k] = ans[j - 1][k];
          }
        }
      }
    }
    std::cout << ans[x.size() - 1][y.size() - 1] << '\\n';
  }
  return 0;
}

#include <iostream>
#include <string>
int main() {
  int n;
  int an[1000];
  int l = 0;
  std::cin >> n;
  std::string x;
  std::string y;
  int ans[1001][1001];
  int j, k;
  for (int i = 0; i < n; i++) {
    std::cin >> x;
    std::cin >> y;
    for (int j = 0; j <= 1000; j++) {
      for (int k = 0; k <= 1000; k++) {
        ans[j][k] = 0;
      }
    }
    for (int j = 1; j < x.size() + 1; j++) {
      for (int k = 1; k < y.size() + 1; k++) {
        if (x[j - 1] == y[k - 1]) {
          ans[j][k] = ans[j - 1][k - 1] + 1;
        } else {
          if (ans[j][k - 1] > ans[j - 1][k]) {
            ans[j][k] = ans[j][k - 1];
          } else {
            ans[j][k] = ans[j - 1][k];
          }
        }
      }
    }
    std::cout << ans[x.size()][y.size()] << '\\n';
  }
  return 0;
}


// ALDS1_10C
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

static const int N = 1000;

int lcs(string X, string Y) {
  vector<vector<int>> c(N, vector<int>(N));
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main() {
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}

// ALDS1_10C
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

static const int N = 1001;

int lcs(string X, string Y) {
  vector<vector<int>> c(N, vector<int>(N));
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main() {
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#define _A_ true
using namespace std;

int main() {
  int n, AC = 0;
  int dp[1010][1010];
  char A[1500], B[1500];
  scanf("%d", &n);
  while (_A_) {
    if (AC == n)
      break;
    scanf("%s", A);
    scanf("%s", B);
    for (int i = 0; i < 1010; i++)
      for (int j = 0; j < 1010; j++)
        dp[i][j] = 0;

    for (int i = 0; i < strlen(A); i++) {
      for (int j = 0; j < strlen(B); j++) {
        if (A[i] == B[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        } else {
          if (dp[i + 1][j] > dp[i][j + 1]) {
            dp[i + 1][j + 1] = dp[i + 1][j];
          } else {
            dp[i + 1][j + 1] = dp[i][j + 1];
          }
        }
      }
    }
    printf("%d\\n", dp[strlen(A)][strlen(B)]);
    AC++;
  }
  return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#define _A_ true
using namespace std;

int main() {
  int n, AC = 0, strA, strB;
  int dp[1010][1010];
  char *A = new char[1500];
  char *B = new char[1500];

  scanf("%d", &n);
  while (_A_) {
    if (AC == n)
      break;
    scanf("%s", A);
    scanf("%s", B);
    for (int i = 0; i < 1010; i++)
      for (int j = 0; j < 1010; j++)
        dp[i][j] = 0;
    strA = strlen(A);
    strB = strlen(B);

    for (int i = 0; i < strA; i++) {
      for (int j = 0; j < strB; j++) {
        if (A[i] == B[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        } else {
          if (dp[i + 1][j] > dp[i][j + 1]) {
            dp[i + 1][j + 1] = dp[i + 1][j];
          } else {
            dp[i + 1][j + 1] = dp[i][j + 1];
          }
        }
      }
    }
    printf("%d\\n", dp[strA][strB]);
    AC++;
  }
  delete[] A;
  delete[] B;

  return 0;
}


#include <iostream>
#include <map>
#include <string>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// 最長共通部分列 ... len(s) == m, len(t) == n とすると, O(mn)
int lcs(std::string s, std::string t) {
  std::vector<std::vector<int>> dp(s.size() + 1,
                                   std::vector<int>(t.size() + 1, 0));

  for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; j < t.size(); ++j) {
      if (s[i] == t[j]) {
        dp[i][j] = (i == 0 ? (j == 0 ? 1 : 0) : 0);
      } else if (i >= 0 && j >= 0 && dp[i - 1][j] >= dp[j][i - 1]) {
        dp[i][j] = dp[i - 1][j];
      } else if (i >= 0 && j >= 0) {
        dp[i][j] = dp[i][j - 1];
      }
    }
  }

  return dp[s.size()][t.size()];
}

int main() {
  int q;
  std::string s, t;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> s >> t;
    cout << lcs(s, t) << endl;
  }

  return 0;
}

#include <iostream>
#include <map>
#include <string>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// 最長共通部分列 ... len(s) == m, len(t) == n とすると, O(mn)
int lcs(std::string s, std::string t) {
  std::vector<std::vector<int>> dp(s.size() + 1,
                                   std::vector<int>(t.size() + 1, 0));

  for (int i = 1; i <= s.size(); ++i) {
    for (int j = 1; j <= t.size(); ++j) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else if (dp[i - 1][j] >= dp[i][j - 1]) {
        dp[i][j] = dp[i - 1][j];
      } else {
        dp[i][j] = dp[i][j - 1];
      }
    }
  }

  return dp[s.size()][t.size()];
}

int main() {
  int q;
  std::string s, t;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> s >> t;
    cout << lcs(s, t) << endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

// I can't understand,so I imitated yutaka watabe's book.
// I think this problem has 5 star rank difficulty.

void calc(char X[], char Y[]) {
  int X_length = 0, Y_length = 0;
  int **table = new int *[1001];
  for (int i = 0; i < 1001; i++) {
    table[i] = new int[1001];
    for (int k = 0; k < 1001; k++)
      table[i][k] = 0;
  }
  for (int i = 0; X[i] != '\\0'; i++)
    X_length++;
  for (int i = 0; Y[i] != '\\0'; i++)
    Y_length++;
  int max_succeed = 0;
  for (int i = 0; i < X_length; i++) {
    for (int k = 0; k < Y_length; k++) {
      if (X[i] == Y[k]) {
        table[i + 1][k + 1] = table[i][k] + 1;
      } else {
        table[i + 1][k + 1] = max(table[i + 1][k], table[i][k + 1]);
      }
      max_succeed = max(max_succeed, table[i + 1][k + 1]);
    }
  }
  printf("%d\\n", max_succeed);
}

int main() {
  int q;
  char X[1001], Y[1001];
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s %s", X, Y);
    calc(X, Y);
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

// I can't understand,so I imitated yutaka watabe's book.
// I think this problem has 5 star rank difficulty.

void calc(char X[], char Y[]) {
  int X_length = 0, Y_length = 0;
  int table[1001][1001];
  for (int i = 0; i < 1001; i++) {
    for (int k = 0; k < 1001; k++)
      table[i][k] = 0;
  }
  for (int i = 0; X[i] != '\\0'; i++)
    X_length++;
  for (int i = 0; Y[i] != '\\0'; i++)
    Y_length++;
  int max_succeed = 0;
  for (int i = 0; i < X_length; i++) {
    for (int k = 0; k < Y_length; k++) {
      if (X[i] == Y[k]) {
        table[i + 1][k + 1] = table[i][k] + 1;
      } else {
        table[i + 1][k + 1] = max(table[i + 1][k], table[i][k + 1]);
      }
      max_succeed = max(max_succeed, table[i + 1][k + 1]);
    }
  }
  printf("%d\\n", max_succeed);
}

int main() {
  int q;
  char X[1001], Y[1001];
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s %s", X, Y);
    calc(X, Y);
  }
  return 0;
}


#include <iostream>

using namespace std;

int dp[1001][1001];

int main() {
  int q, m, n;
  cin >> q;

  while (q-- > 0) {
    string x, y;
    cin >> x >> y;
    x = ' ' + x;
    y = ' ' + y;
    m = x.length();
    n = y.length();
    for (int i = 1; i <= m; i++)
      dp[i][0];
    for (int i = 1; i <= n; i++)
      dp[0][i];

    int res = 0;
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {
        if (x[i] == y[j])
          dp[i][j] = dp[i - 1][j - 1] + 1;
        else
          dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }

    cout << dp[m][n] - 1 << endl;
  }

  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

static const int N = 1000;
int dp[N + 1][N + 1];

int lcs(string x, string y) {
  int m = x.length();
  int n = y.length();
  x = ' ' + x;
  y = ' ' + y;

  dp[0][0] = 0;
  for (int i = 1; i <= m; i++)
    dp[i][0] = 0;
  for (int j = 1; j <= n; j++)
    dp[0][j] = 0;

  int res = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (x[i] == y[j])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
  }

  return dp[m][n];
}

int main() {
  int n;
  cin >> n;
  string x1, x2;
  for (int i = 0; i < n; i++) {
    cin >> x1 >> x2;
    cout << lcs(x1, x2) << endl;
  }
  return 0;
}


#include <iostream>
#include <string>

#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

int q;
string s, t;
int dp[151][151];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> q;
  rep(k, q) {
    cin >> s >> t;
    rep(i, 101) rep(j, 101) dp[i][j] = 0;
    rep(i, s.size()) {
      rep(j, t.size()) {
        if (s[i] == t[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[s.size()][t.size()] << "\\n";
  }
  return 0;
}

#include <iostream>
#include <string>
using namespace std;

int dp[1001][1001];
string s, t;
int n, m, a;

int main() {
  cin >> a;
  for (int b = 0; b < a; b++) {
    cin >> s >> t;
    for (int i = 0; i <= 1000; i++)
      for (int j = 0; j <= 1000; j++)
        dp[i][j] = 0;
    m = s.size();
    n = t.size();
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {
        if (s[i - 1] == t[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else {
          dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
      }
    }
    cout << dp[m][n] << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)

string str1, str2;
int dp[1001][1001];
int k;

int solve(int i, int j) {
  if (dp[i][j] > 0)
    return dp[i][j];
  if (i >= str1.size() || j >= str2.size()) {
    if (i < str1.size()) {
      return solve(i + 1, k);
    } else {
      return 0;
    }
  }
  if (str1[i] == str2[j]) {
    k = j + 1;
    int n, m = 0;
    for (int l = i + 1; l < str1.size(); l++) {
      n = solve(l, j + 1);
      m = (n > m) ? n : m;
    }
    dp[i][j] = m + 1;
    return dp[i][j];
  } else {
    return solve(i, j + 1);
  }
}

int main() {
  int q, n, ans = 0;
  cin >> q;
  cin.ignore();
  REP(i, q) {
    getline(cin, str1);
    getline(cin, str2);
    if (str1.size() < str2.size())
      swap(str1, str2);
    fill(&dp[0][0], &dp[1001][0], -1);
    for (int j = str1.size() - 1; j >= 0; j--) {
      n = solve(j, 0);
      ans = (n > ans) ? n : ans;
    }
    cout << ans << endl;
    ans = 0;
  }
}

#include <algorithm>
#include <iostream>
using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)

string str1, str2;
int dp[1001][1001];

void solve() {
  REP(i, str1.size())
  if (str1[i] == str2[str2.size() - 1])
    dp[i][str2.size() - 1] = 1;
  else
    dp[i][str2.size() - 1] = 0;
  for (int i = str2.size() - 2; i >= 0; i--)
    if (str1[str1.size() - 1] == str2[i])
      dp[str1.size() - 1][i] = 1;
    else
      dp[str1.size() - 1][i] = dp[str1.size() - 1][i + 1];
  for (int i = str1.size() - 2; i >= 0; i--) {
    for (int j = str2.size() - 2; j >= 0; j--) {
      if (str1[i] == str2[j])
        dp[i][j] = dp[i + 1][j + 1] + 1;
      else
        dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
    }
  }
}

int main() {
  int q, m;
  cin >> q;
  cin.ignore();
  REP(i, q) {
    getline(cin, str1);
    getline(cin, str2);
    fill(&dp[0][0], &dp[1001][0], -1);
    solve();
    m = dp[0][0];
    swap(str1, str2);
    fill(&dp[0][0], &dp[1001][0], -1);
    solve();
    cout << ((m > dp[0][0]) ? m : dp[0][0]) << endl;
  }
}


#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

string X;
string Y;

int calc(int x, int y) {
  if (X[x] == '\\0')
    return 0;
  if (y == string::npos)
    return 0;

  int unuse = calc(x + 1, y);
  int use = 0;
  int y_target = Y.find(X[x], y);
  if (y_target == string::npos) {
    use = 0;
  } else {
    use = calc(x + 1, y_target + 1) + 1;
  }
  return max(unuse, use);
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> X;
    cin >> Y;
    cout << calc(0, 0) << endl;
  }

  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

string X;
string Y;

int calc(int x, int y, vector<vector<int>> &Memo) {
  if (X[x] == '\\0' || Y[y] == '\\0')
    return 0;
  if (Memo[x][y] != -1)
    return Memo[x][y];

  int unuse = calc(x + 1, y, Memo);
  int use = 0;
  int y_target = Y.find(X[x], y);
  if (y_target == string::npos) {
    use = 0;
  } else {
    use = calc(x + 1, y_target + 1, Memo) + 1;
  }
  return Memo[x][y] = max(unuse, use);
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> X;
    cin >> Y;
    vector<int> tmp(Y.size(), -1);
    vector<vector<int>> Memo(X.size(), tmp);
    cout << calc(0, 0, Memo) << endl;
  }

  return 0;
}


#include <bits/stdc++.h>

#define MOD 1000000007
#define INF (1 << 30)
#define INFL (1 << 62)
#define pe(str) return cout << (str) << endl, 0
#define px(str) cout << (str) << endl, exit(0)
#define accu(ac, v) cout << setprecision(ac) << v << endl
#define bpc(a) __builtin_popcount(a)
#define pr(str) cout << (str) << endl
#define prpr(str) cout << str << endl
#define db(str) cerr << "debug:" << (str) << endl
#define dbdb(str) cerr << "debugs:" << str << endl
#define re(i, n) for (int i = 0; i < (n); i++)
#define rre(i, n) for (int i = (n); i >= 0; i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b); i >= (a); i--)
#define bw(a, b, c) (((a) <= (b)) && ((b) <= (c)))
#define hello cout << "hello" << endl
#define spre(a) setprecision(a)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define s3(C, T, F) ((C) ? (T) : (F))
#define max3(a, b, c) max((a), max((b), (c)))
#define min3(a, b, c) min((a), min((b), (c)))
#define max4(a, b, c, d) max((a), max((b), max((c), (d))))
#define min4(a, b, c, d) min((a), min((b), min((c), (d))))
#define enl cout << endl
#define declare(t, n)                                                          \\
  t n;                                                                         \\
  cin >> n

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef complex<int> point;

template <class InputIterator>
void dump(InputIterator first, InputIterator last, char delim = ' ') {
  for (InputIterator it = first; it != last; it++) {
    if (it != first)
      cout << delim;
    cout << *it;
  }
}

ull p(ull x, ull y) {
  if (y == 0)
    return 1;
  ull A = p(x, y / 2) % MOD;
  return (y & 1 ? ((A * A) % MOD * x) % MOD : (A * A) % MOD);
  // return (y&1?((A*A)*x):(A*A));
}

template <class T> void swp(T &a, T &b) {
  T t = a;
  a = b;
  b = t;
}

int main(void) {
  int dp[100][100];
  string a, b;
  int n;
  cin >> n;

  while (n--) {
    cin >> a >> b;
    re(i, a.size()) re(j, b.size()) dp[i][j] = 0;
    rep(i, 1, a.size() + 1) {
      rep(j, 1, b.size() + 1) {
        dp[i][j] = max(dp[i - 1][j - 1] + (a[i - 1] == b[j - 1]), dp[i - 1][j]);
        dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      }
    }
    cout << dp[a.size()][b.size()] << endl;
  }
  return 0;
}

#include <bits/stdc++.h>

#define MOD 1000000007
#define INF (1 << 30)
#define INFL (1 << 62)
#define pe(str) return cout << (str) << endl, 0
#define px(str) cout << (str) << endl, exit(0)
#define accu(ac, v) cout << setprecision(ac) << v << endl
#define bpc(a) __builtin_popcount(a)
#define pr(str) cout << (str) << endl
#define prpr(str) cout << str << endl
#define db(str) cerr << "debug:" << (str) << endl
#define dbdb(str) cerr << "debugs:" << str << endl
#define re(i, n) for (int i = 0; i < (n); i++)
#define rre(i, n) for (int i = (n); i >= 0; i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b); i >= (a); i--)
#define bw(a, b, c) (((a) <= (b)) && ((b) <= (c)))
#define hello cout << "hello" << endl
#define spre(a) setprecision(a)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define s3(C, T, F) ((C) ? (T) : (F))
#define max3(a, b, c) max((a), max((b), (c)))
#define min3(a, b, c) min((a), min((b), (c)))
#define max4(a, b, c, d) max((a), max((b), max((c), (d))))
#define min4(a, b, c, d) min((a), min((b), min((c), (d))))
#define enl cout << endl
#define declare(t, n)                                                          \\
  t n;                                                                         \\
  cin >> n

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef complex<int> point;

template <class InputIterator>
void dump(InputIterator first, InputIterator last, char delim = ' ') {
  for (InputIterator it = first; it != last; it++) {
    if (it != first)
      cout << delim;
    cout << *it;
  }
}

ull p(ull x, ull y) {
  if (y == 0)
    return 1;
  ull A = p(x, y / 2) % MOD;
  return (y & 1 ? ((A * A) % MOD * x) % MOD : (A * A) % MOD);
  // return (y&1?((A*A)*x):(A*A));
}

template <class T> void swp(T &a, T &b) {
  T t = a;
  a = b;
  b = t;
}

int main(void) {
  int dp[1001][1001];
  string a, b;
  int n;
  cin >> n;

  while (n--) {
    cin >> a >> b;
    re(i, a.size()) re(j, b.size()) dp[i][j] = 0;
    rep(i, 1, a.size() + 1) rep(j, 1, b.size() + 1) dp[i][j] = max3(
        dp[i - 1][j - 1] + (a[i - 1] == b[j - 1]), dp[i - 1][j], dp[i][j - 1]);
    cout << dp[a.size()][b.size()] << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
#include <tuple>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;

using namespace std;
int dp[1005][1005];

void dfs(int i, int j, string q, string b) {
  int x = j;
  string tar = b.substr(x, 1);
  while (x < b.length() && q != tar) {
    x++;
    tar = b.substr(x, 1);
  }
  if (i == 0) {
    while (x < b.length()) {
      x++;
      dp[i][x] = 1;
    }
    return;
  }
  while (x < b.length()) {
    x++;
    dp[i][x] = max(dp[i - 1][j] + 1, dp[i][x]);
  }
  dp[i][j] = max(dp[i][j], dp[i - 1][j]);
  return;
}

int main() {
  int n;
  cin >> n;
  REP(k, n) {
    REP(i, 1005) REP(j, 1005) dp[i][j] = 0;
    string a, b;
    cin >> a >> b;
    REP(i, a.length()) {
      string q = a.substr(i, 1);
      REP(j, b.length() + 1) dfs(i, j, q, b);
    }
    cout << dp[a.length() - 1][b.length()] << endl;
  }
  return 0;
}

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;

using namespace std;
int dp[1005][1005];

int main() {
  int n;
  cin >> n;
  REP(k, n) {
    REP(i, 1005) REP(j, 1005) dp[i][j] = 0;
    string a, b;
    cin >> a >> b;
    REP(i, a.length()) {
      string q = a.substr(i, 1);
      REP(j, b.length()) {
        string t = b.substr(j, 1);
        if (q == t) {
          if (i == 0 || j == 0)
            dp[i][j] = 1;
          else
            dp[i][j] = (dp[i - 1][j] > dp[i][j - 1])
                           ? max(dp[i - 1][j - 1] + 1, dp[i - 1][j])
                           : max(dp[i - 1][j - 1] + 1, dp[i][j - 1]);
        } else if (i != 0 && j != 0)
          dp[i][j] =
              (dp[i - 1][j] > dp[i][j - 1]) ? dp[i - 1][j] : dp[i][j - 1];
        else if (i != 0)
          dp[i][j] = dp[i - 1][j];
        else
          dp[i][j] = dp[i][j - 1];
      }
    }
    cout << dp[a.length() - 1][b.length() - 1] << endl;
  }
  return 0;
}


#include <cstring>
#include <iostream>

using namespace std;

/**
 *  lcs(m,n) =
 *  if x[m] == y[n] lcs[m-1,n-1]+1
 *  max(lcs[m-1,n],lcs[m,n-1])
 *
 */

string x, y;

const int q = 150;

int c[q][q];

int lcs(int m, int n) {
  if (m == -1 || n == -1)
    return 0;
  if (x[m] == y[n])
    return lcs(m - 1, n - 1) + 1;
  int &cc = c[m][n];
  if (cc != -1)
    return cc;
  int xx = lcs(m - 1, n);
  int yy = lcs(m, n - 1);
  cc = xx > yy ? xx : yy;
  return cc;
}

int main() {
  int n = 0;
  x.resize(q);
  y.resize(q);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    cin >> y;
    cout << lcs(x.size() - 1, y.size() - 1) << endl;
    x.clear();
    y.clear();

    memset(c, -1, sizeof(c));
  }
}

#include <cstring>
#include <iostream>

using namespace std;

/**
 *  lcs(m,n) =
 *  if x[m] == y[n] lcs[m-1,n-1]+1
 *  max(lcs[m-1,n],lcs[m,n-1])
 *
 */

string x, y;

const int N = 1000;

int c[N][N];

int lcs(int m, int n) {
  if (m == -1 || n == -1)
    return 0;
  if (x[m] == y[n])
    return lcs(m - 1, n - 1) + 1;
  int &cc = c[m][n];
  if (cc != -1)
    return cc;
  int xx = lcs(m - 1, n);
  int yy = lcs(m, n - 1);
  cc = xx > yy ? xx : yy;
  return cc;
}

int main() {
  int n = 0;
  x.reserve(N);
  y.reserve(N);
  cin >> n;
  for (int i = 0; i < n; i++) {
    memset(c, -1, sizeof(c));
    cin >> x;
    cin >> y;
    cout << lcs(x.size() - 1, y.size() - 1) << endl;
    x.clear();
    y.clear();
  }
}


#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

const int MAX_LENGTH = 256;

char A[MAX_LENGTH + 1];
char B[MAX_LENGTH + 1];

int tu[MAX_LENGTH][MAX_LENGTH];

void lcs(int, int);

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> A >> B;
    int lA = strlen(A), lB = strlen(B);
    lcs(lA, lB);
    cout << tu[lA][lB] << endl;
  }
}

void lcs(int lA, int lB) {
  for (int i = 0; i < lA; ++i)
    tu[0][i] = 0;
  for (int i = 0; i < lB; ++i)
    tu[i][0] = 0;

  for (int i = 1; i <= lA; i++) {
    for (int j = 1; j <= lB; j++) {
      if (A[i - 1] == B[j - 1])
        tu[i][j] = tu[i - 1][j - 1] + 1;
      else
        tu[i][j] = max(tu[i][j - 1], tu[i - 1][j]);
    }
  }
}

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

const int MAX_LENGTH = 1024;

char A[MAX_LENGTH + 1];
char B[MAX_LENGTH + 1];

int tu[MAX_LENGTH][MAX_LENGTH];

void lcs(int, int);

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> A >> B;
    int lA = strlen(A), lB = strlen(B);
    lcs(lA, lB);
    cout << tu[lA][lB] << endl;
  }
}

void lcs(int lA, int lB) {
  for (int i = 0; i < lA; ++i)
    tu[0][i] = 0;
  for (int i = 0; i < lB; ++i)
    tu[i][0] = 0;

  for (int i = 1; i <= lA; i++) {
    for (int j = 1; j <= lB; j++) {
      if (A[i - 1] == B[j - 1])
        tu[i][j] = tu[i - 1][j - 1] + 1;
      else
        tu[i][j] = max(tu[i][j - 1], tu[i - 1][j]);
    }
  }
}


#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES

#include <map>
#include <math.h>

#define SENTINEL 1000000001

#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)

using namespace std;

int LCS[1000][1000];

void solve(string x, string y) {
  for (int i = 0; i != x.size(); i++) {
    for (int j = 0; j != y.size(); j++) {
      if (x[i] == y[j]) {
        LCS[i + 1][j + 1] = LCS[i][j] + 1;
      } else {
        LCS[i + 1][j + 1] = max(LCS[i][j + 1], LCS[i + 1][j]);
      }
    }
  }

  cout << LCS[x.size()][y.size()] << endl;
}

int main() {
  int q;
  cin >> q;

  for (int i = 0; i < 1000; i++) {
    LCS[0][i] = 0;
    LCS[i][0] = 0;
  }

  for (int i = 0; i < q; i++) {
    string x, y;
    cin >> x >> y;
    solve(x, y);
  }
  return 0;
}

#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES

#include <map>
#include <math.h>

#define SENTINEL 1000000001

#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)

using namespace std;

int LCS[1010][1010];

void solve(string x, string y) {
  for (int i = 0; i != x.size(); i++) {
    for (int j = 0; j != y.size(); j++) {
      if (x[i] == y[j]) {
        LCS[i + 1][j + 1] = LCS[i][j] + 1;
      } else {
        LCS[i + 1][j + 1] = max(LCS[i][j + 1], LCS[i + 1][j]);
      }
    }
  }

  cout << LCS[x.size()][y.size()] << endl;
}

int main() {
  int q;
  cin >> q;

  for (int i = 0; i < 1000; i++) {
    LCS[0][i] = 0;
    LCS[i][0] = 0;
  }

  for (int i = 0; i < q; i++) {
    string x, y;
    cin >> x >> y;
    solve(x, y);
  }
  return 0;
}


#include <cstring>
#include <iostream>
#include <string>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define clr(a, v) memset((a), (v), sizeof(a))

int q;
int dp[1000][1000];
std::string s, t;

int rec(int i, int j) {
  int &ret = dp[i][j];

  if (~ret)
    return ret;

  if (i == s.size() || j == t.size())
    return 0;

  ret = 0;

  if (s[i] == t[j])
    ret = std::max(ret, rec(i + 1, j + 1) + 1);

  ret = std::max(ret, std::max(rec(i + 1, j), rec(i, j + 1)));

  return ret;
}

int main() {
  std::cin >> q;
  while (q--) {
    std::cin >> s >> t;

    clr(dp, -1);

    std::cout << rec(0, 0) << std::endl;
  }

  return 0;
}

#include <cstring>
#include <iostream>
#include <string>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define clr(a, v) memset((a), (v), sizeof(a))

int q;
int dp[1001][1001];
std::string s, t;

int rec(int i, int j) {
  int &ret = dp[i][j];

  if (~ret)
    return ret;

  if (i == s.size() || j == t.size())
    return 0;

  ret = 0;

  if (s[i] == t[j])
    ret = std::max(ret, rec(i + 1, j + 1) + 1);

  ret = std::max(ret, std::max(rec(i + 1, j), rec(i, j + 1)));

  return ret;
}

int main() {
  std::cin >> q;
  while (q--) {
    std::cin >> s >> t;

    clr(dp, -1);

    std::cout << rec(0, 0) << std::endl;
  }

  return 0;
}


#include <iostream>
#include <string>

using namespace std;

// L[i][j] X[0]..X[i]??¨X[0]..Y[j]???LCS
int L[1000][1000] = {};
int main() {
  int testnum;
  cin >> testnum;
  for (int t = 0; t < testnum; ++t) {
    string X, Y;
    cin >> X >> Y;

    for (int i = 1; i <= X.length(); ++i) {
      for (int j = 1; j <= Y.length(); ++j) {
        if (X[i - 1] == Y[j - 1])
          L[i][j] = 1 + L[i - 1][j - 1];
        else
          L[i][j] = max(L[i][j - 1], L[i - 1][j]);
      }
    }

    cout << L[X.length()][Y.length()] << endl;
  }

  return 0;
}

#include <iostream>
#include <string>

using namespace std;

// L[i][j] X[0]..X[i]??¨X[0]..Y[j]???LCS
int L[1001][1001] = {};
int main() {
  int testnum;
  cin >> testnum;
  for (int t = 0; t < testnum; ++t) {
    string X, Y;
    cin >> X >> Y;

    for (int i = 1; i <= X.length(); ++i) {
      for (int j = 1; j <= Y.length(); ++j) {
        if (X[i - 1] == Y[j - 1])
          L[i][j] = 1 + L[i - 1][j - 1];
        else
          L[i][j] = max(L[i][j - 1], L[i - 1][j]);
      }
    }

    cout << L[X.length()][Y.length()] << endl;
  }

  return 0;
}


#include "iostream"
#include "string.h"

using namespace std;

int L[1001][1001];

int lcs(char s1[], char s2[], int l1, int l2) {

  if (L[l1][l2] != 0)
    return L[l1][l2];

  if (l1 == 0 || l2 == 0)
    return 0;
  else if (s1[l1 - 1] == s2[l2 - 1])
    L[l1][l2] = lcs(s1, s2, l1 - 1, l2 - 1) + 1;
  else {
    int lsc1 = lcs(s1, s2, l1 - 1, l2);
    int lsc2 = lcs(s1, s2, l1, l2 - 1);

    if (lsc1 > lsc2)
      L[l1][l2] = lsc1;
    else
      L[l1][l2] = lsc2;
  }

  return L[l1][l2];
}

int main() {

  int n;
  char s1[1000], s2[1000];

  cin >> n;

  int ans[150];

  for (int i = 0; i < n; i++) {
    cin >> s1;
    cin >> s2;

    ans[i] = lcs(s1, s2, strlen(s1), strlen(s2));

    for (int j = 0; j <= strlen(s1); j++) {
      for (int k = 0; k <= strlen(s2); k++) {
        L[j][k] = 0;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

#include "iostream"
#include "string.h"

using namespace std;

int L[1001][1001];

int lcs(char s1[], char s2[], int l1, int l2) {

  if (L[l1][l2] != 0)
    return L[l1][l2];

  if (l1 == 0 || l2 == 0)
    return 0;
  else if (s1[l1 - 1] == s2[l2 - 1])
    L[l1][l2] = lcs(s1, s2, l1 - 1, l2 - 1) + 1;
  else {
    int lsc1 = lcs(s1, s2, l1 - 1, l2);
    int lsc2 = lcs(s1, s2, l1, l2 - 1);

    if (lsc1 > lsc2)
      L[l1][l2] = lsc1;
    else
      L[l1][l2] = lsc2;
  }

  return L[l1][l2];
}

int main() {

  int n;
  char s1[1000], s2[1000];

  cin >> n;

  int ans[150];

  for (int i = 0; i < n; i++) {
    cin >> s1;
    cin >> s2;

    int l1 = strlen(s1), l2 = strlen(s2);

    ans[i] = lcs(s1, s2, l1, l2);

    for (int j = 0; j <= l1; j++) {
      for (int k = 0; k <= l2; k++) {
        L[j][k] = 0;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


///
// File:  alds1_10_c.cpp
// Author: ymiyamoto
//
// Created on Tue Oct 17 01:36:16 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;
static uint32_t dp[1000][1000];

static void init_dp(uint32_t len1, uint32_t len2) {
  for (uint32_t i = 0; i < len1; i++) {
    dp[i][0] = 0;
  }
  for (uint32_t i = 0; i < len2; i++) {
    dp[0][i] = 0;
  }
}

int32_t main() {
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    string str1, str2;
    cin >> str1;
    cin >> str2;
    init_dp(str1.size(), str2.size());
    for (uint32_t i = 1; i <= str1.size(); i++) {
      for (uint32_t j = 1; j <= str2.size(); j++) {
        if (str1[i - 1] == str2[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else {
          dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
      }
    }
    cout << dp[str1.size()][str2.size()] << endl;
  }

  return 0;
}

///
// File:  alds1_10_c.cpp
// Author: ymiyamoto
//
// Created on Tue Oct 17 01:36:16 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;
static uint32_t dp[1001][1001];

static void init_dp(uint32_t len1, uint32_t len2) {
  for (uint32_t i = 0; i < len1; i++) {
    dp[i][0] = 0;
  }
  for (uint32_t i = 0; i < len2; i++) {
    dp[0][i] = 0;
  }
}

int32_t main() {
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    string str1, str2;
    cin >> str1;
    cin >> str2;
    init_dp(str1.size(), str2.size());
    for (uint32_t i = 1; i <= str1.size(); i++) {
      for (uint32_t j = 1; j <= str2.size(); j++) {
        if (str1[i - 1] == str2[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else {
          dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
      }
    }
    cout << dp[str1.size()][str2.size()] << endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define NIL -1
using namespace std;

int count(const string &X, int i, const string Y, int j,
          vector<vector<int>> &MEMO) {
  if (i >= X.size() || j >= Y.size())
    return 0;
  if (MEMO[i][j] != NIL)
    return MEMO[i][j];
  int next_Y = count(X, i, Y, j + 1, MEMO);
  int next_X = count(X, i + 1, Y, j, MEMO);
  int max_ = max(next_Y, next_X);
  int j_tmp = j;
  while (X[i] != Y[j_tmp]) {
    j_tmp++;
    if (j_tmp >= Y.size())
      return max_;
  }
  int saiyou = count(X, i + 1, Y, j_tmp + 1, MEMO) + 1;
  if (max_ < saiyou)
    max_ = saiyou;
  return MEMO[i][j] = max_;
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string X, Y;
    cin >> X >> Y;
    vector<vector<int>> MEMO(X.size(), vector<int>(Y.size(), NIL));
    cout << count(X, 0, Y, 0, MEMO) << endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define NIL -1
using namespace std;

int count(const string &X, int i, const string Y, int j,
          vector<vector<int>> &MEMO) {
  if (i >= X.size() || j >= Y.size())
    return 0;
  if (MEMO[i][j] != NIL)
    return MEMO[i][j];
  int j_tmp = j;
  int saiyou = 0;
  while (j_tmp < Y.size()) {
    if (X[i] == Y[j_tmp]) {
      saiyou = count(X, i + 1, Y, j_tmp + 1, MEMO) + 1;
      break;
    };
    j_tmp++;
  }
  int next_X = count(X, i + 1, Y, j, MEMO);
  int next_Y = count(X, i, Y, j + 1, MEMO);
  return MEMO[i][j] = max({saiyou, next_X, next_Y});
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string X, Y;
    cin >> X >> Y;
    vector<vector<int>> MEMO(X.size(), vector<int>(Y.size(), NIL));
    cout << count(X, 0, Y, 0, MEMO) << endl;
  }
  return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int dat[1024][1024];
int getLcbLen(char *x, int xe, char *y, int ye) {
  cout << xe << ":" << ye << endl;
  if (xe <= 0 || ye <= 0)
    return 0;
  if (dat[xe][ye] != -1)
    return dat[xe][ye];
  return dat[xe][ye] =
             (x[xe - 1] == y[ye - 1] ? 1 + getLcbLen(x, xe - 1, y, ye - 1)
                                     : max(getLcbLen(x, xe - 1, y, ye),
                                           getLcbLen(x, xe, y, ye - 1)));
}

int main() {
  int set;
  scanf("%d", &set);

  while (set--) {
    char x[1024], y[1024];
    scanf("%s %s", x, y);

    for (int i = 0; i < 1024; i++) {
      for (int k = 0; i < 1024; k++) {
        dat[i][k] = -1;
      }
    }
    printf("%d\\n", getLcbLen(x, (int)strlen(x), y, (int)strlen(y)));
  }
  return 0;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int dat[1024][1024];
int getLcbLen(char *x, int xe, char *y, int ye) {
  if (xe <= 0 || ye <= 0)
    return 0;
  if (dat[xe][ye] != -1)
    return dat[xe][ye];
  return dat[xe][ye] =
             (x[xe - 1] == y[ye - 1] ? 1 + getLcbLen(x, xe - 1, y, ye - 1)
                                     : max(getLcbLen(x, xe - 1, y, ye),
                                           getLcbLen(x, xe, y, ye - 1)));
}

int main() {
  int set;
  scanf("%d", &set);

  while (set--) {
    char x[1024], y[1024];
    scanf("%s %s", x, y);

    for (int i = 0; i < 1024; i++) {
      for (int k = 0; k < 1024; k++) {
        dat[i][k] = -1;
      }
    }
    printf("%d\\n", getLcbLen(x, (int)strlen(x), y, (int)strlen(y)));
  }
  return 0;
}


#include <cmath>
#include <cstdio>
#define MAX 1001
using namespace std;

int Lcc(const char *X, const char *Y) {
  int lcc = 0;
  int dp[MAX][MAX];
  for (int i = 0; i < MAX; i++)
    for (int j = 0; j < MAX; j++)
      dp[i][j] = 0;

  int x = 0, y = 0;
  for (int i = 0;; i++) {
    if (X[i] == ',') {
      x = i;
      break;
    }
    for (int j = 0;; j++) {
      if (Y[j] == ',') {
        y = j;
        break;
      } else {
        if (X[i] == Y[j]) {
          dp[i + 1][j + 1] = fmax(dp[i][j] + 1, dp[i + 1][j]);
        } else {
          dp[i + 1][j + 1] = fmax(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
  }
  return dp[x - 1][y - 1];
}

int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < (q); i++) {
    char X[MAX], Y[MAX];
    for (int i = 0; i < MAX; i++) {
      X[i] = ',';
      Y[i] = ',';
    }
    scanf(" %s", X);
    scanf(" %s", Y);
    int LCC = Lcc(X, Y);
    printf("%d\\n", LCC);
  }
  return 0;
}

#include <cmath>
#include <cstdio>
#define MAX 1002
using namespace std;

int Lcc(const char *X, const char *Y) {
  int lcc = 0;
  int dp[MAX][MAX];
  for (int i = 0; i < MAX; i++)
    for (int j = 0; j < MAX; j++)
      dp[i][j] = 0;

  int x = 1, y = 1;
  for (int i = 0;; i++) {
    if (X[i] == ',') {
      x = i;
      break;
    }
    for (int j = 0;; j++) {
      if (Y[j] == ',') {
        y = j;
        break;
      }
      if (Y[j] == ',') {
        y = j;
        break;
      } else {
        if (X[i] == Y[j]) {
          dp[i + 1][j + 1] = fmax(dp[i][j] + 1, dp[i + 1][j]);
        } else {
          dp[i + 1][j + 1] = fmax(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
  }
  return dp[x - 1][y - 1];
}

int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < (q); i++) {
    char X[MAX], Y[MAX];
    for (int i = 0; i < MAX; i++) {
      X[i] = ',';
      Y[i] = ',';
    }
    scanf(" %s", X);
    scanf(" %s", Y);
    int LCC = Lcc(X, Y);
    printf("%d\\n", LCC);
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int q;
string X, Y;
int L[1001][1001];

int max(int i, int j) { return i > j ? i : j; }

int getL(int i, int j) {
  if (L[i][j] != -1)
    return L[i][j];

  if (i == 0 || j == 0)
    return 0;
  if (X[i - 1] == Y[j - 1])
    return 1 + getL(i - 1, j - 1);
  return max(getL(i, j - 1), getL(i - 1, j));
}

int main() {

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> X >> Y;
    for (int j = 0; j <= X.size(); j++) {
      for (int k = 0; k <= Y.size(); k++)
        L[j][k] = -1;
    }
    cout << getL(X.size(), Y.size()) << endl;
  }
}

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int q;
string X, Y;
int L[1001][1001];

int max(int i, int j) { return i > j ? i : j; }

int getL(int i, int j) {
  if (L[i][j] != -1)
    return L[i][j];

  int res;

  if (i == 0 || j == 0)
    res = 0;
  else if (X[i - 1] == Y[j - 1])
    res = 1 + getL(i - 1, j - 1);
  else
    res = max(getL(i, j - 1), getL(i - 1, j));

  L[i][j] = res;
  return res;
}

int main() {

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> X >> Y;
    for (int j = 0; j <= X.size(); j++) {
      for (int k = 0; k <= Y.size(); k++)
        L[j][k] = -1;
    }
    cout << getL(X.size(), Y.size()) << endl;
  }
}


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1000
void solve(void);
int q, count[MAX][MAX] = {}, xlength, ylength;
char X[MAX], Y[MAX];

void solve(void) {
  int i, j;

  xlength = strlen(X);
  ylength = strlen(Y);

  for (i = 1; i <= xlength; i++) {
    for (j = 1; j <= ylength; j++) {
      if (X[i - 1] == Y[j - 1])
        count[i][j] = count[i - 1][j - 1] + 1;
      else if (count[i - 1][j] >= count[i][j - 1])
        count[i][j] = count[i - 1][j];
      else
        count[i][j] = count[i][j - 1];
    }
  }
}

int main() {
  int i;

  scanf("%d", &q);

  for (i = 1; i <= q; i++) {
    scanf("%s", X);
    scanf("%s", Y);
    solve();
    printf("%d\\n", count[xlength][ylength]);
  }

  /*for(i=0;i<q;i++){
    printf("%d\\n",count[][]);
    }*/

  return 0;
}

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1001
void solve(void);
int q, count[MAX][MAX] = {}, xlength, ylength;
char X[MAX], Y[MAX];

void solve(void) {
  int i, j;

  xlength = strlen(X);
  ylength = strlen(Y);

  for (i = 1; i <= xlength; i++) {
    for (j = 1; j <= ylength; j++) {
      if (X[i - 1] == Y[j - 1])
        count[i][j] = count[i - 1][j - 1] + 1;
      else if (count[i - 1][j] >= count[i][j - 1])
        count[i][j] = count[i - 1][j];
      else
        count[i][j] = count[i][j - 1];
    }
  }
}

int main() {
  int i;

  scanf("%d", &q);

  for (i = 1; i <= q; i++) {
    scanf("%s", X);
    scanf("%s", Y);
    solve();
    printf("%d\\n", count[xlength][ylength]);
  }

  /*for(i=0;i<q;i++){
    printf("%d\\n",count[][]);
    }*/

  return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int dp[1001][1001];
int n;
int strlen_1(char a[]) {
  int len = 0;
  while (a[len] != '\\0')
    len++;
  return len;
}
int solve(char a[], char b[]) {

  int maxn = 0;
  int len1 = strlen_1(a), len2 = strlen_1(b);

  for (int i = 1; i <= strlen_1(a); i++)
    for (int j = 1; j <= strlen_1(b); j++) {
      if (a[i - 1] == b[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = max(
            dp[i - 1][j],
            dp[i][j - 1]); // 这个只是表示某个状态的不是最大的，这个是自己设定的
      maxn = max(maxn, dp[i][j]);
    }
  return maxn;
}
char a[1001], b[1001];
int main() {

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    cout << solve(a, b) << endl;
  }
  return 0;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int dp[1001][1001];
int solve(string a, string b) {

  int maxn = 0;
  int len1 = a.size(), len2 = b.size();

  for (int i = 1; i <= len1; i++)
    for (int j = 1; j <= len2; j++) {
      if (a[i - 1] == b[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = max(
            dp[i - 1][j],
            dp[i][j - 1]); // 这个只是表示某个状态的不是最大的，这个是自己设定的
      maxn = max(maxn, dp[i][j]);
    }
  return maxn;
}
int main() {
  int n;
  string a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    cout << solve(a, b) << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

const int s = 1000;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int q;
  string X, Y;
  static unsigned int dp[s][s] = {0};

  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[1][0] = 0;

  cin >> q;
  for (int k = 0; k < q; k++) {
    cin >> X >> Y;
    int i, j;
    for (i = 0; i < X.size(); i++) {
      for (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][j + 1], dp[i + 1][j]);
      }
    }
    cout << dp[i][j] << "\\n";
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

const int s = 1001;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int q;
  static unsigned int dp[s][s] = {0};

  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[1][0] = 0;

  cin >> q;
  for (int k = 0; k < q; k++) {
    string X, Y;
    cin >> X >> Y;
    int i, j;
    for (i = 0; i < X.size(); i++) {
      for (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][j + 1], dp[i + 1][j]);
      }
    }
    cout << dp[i][j] << "\\n";
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define MAX 1000

int solve(string x, string y) {
  int lcs[MAX + 1][MAX + 1];
  int xl = x.size();
  int yl = y.size();

  int i, j;
  for (i = 0; i < xl; i++)
    lcs[i][0] = 0;
  for (j = 0; i < yl; j++)
    lcs[0][j] = 0;

  // shift
  x = " " + x;
  y = " " + y;

  int maxlcs = 0;
  for (i = 1; i <= xl; i++) {
    for (j = 1; j <= yl; j++) {
      if (x[i] == y[j]) {
        lcs[i][j] = lcs[i - 1][j - 1] + 1;
      } else {
        int a = lcs[i][j - 1];
        int b = lcs[i - 1][j];
        lcs[i][j] = max(a, b);
      }
      maxlcs = max(maxlcs, lcs[i][j]);
    }
  }
  return maxlcs;
}

int main() {
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1;
    cin >> s2;
    cout << solve(s1, s2) << endl;
  }
}

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define MAX 1000

int solve(string x, string y) {
  int xl = x.size();
  int yl = y.size();
  int lcs[MAX + 1][MAX + 1];

  int i, j;
  for (i = 0; i < xl; i++)
    lcs[i][0] = 0;
  for (j = 0; j < yl; j++)
    lcs[0][j] = 0;

  // shift
  x = " " + x;
  y = " " + y;

  int maxlcs = 0;
  for (i = 1; i <= xl; i++) {
    for (j = 1; j <= yl; j++) {
      if (x[i] == y[j]) {
        lcs[i][j] = lcs[i - 1][j - 1] + 1;
      } else {
        int a = lcs[i][j - 1];
        int b = lcs[i - 1][j];
        lcs[i][j] = max(a, b);
      }
      maxlcs = max(maxlcs, lcs[i][j]);
    }
  }
  return maxlcs;
}

int main() {
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1;
    cin >> s2;
    cout << solve(s1, s2) << endl;
  }
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

// ---------------------
// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int dp[1000][1000];

int main() {
  int q;
  cin >> q;
  REP(loop, q) {
    char S[1000], T[1000];
    cin >> S >> T;

    REP(i, strlen(S)) {
      REP(j, strlen(T)) { dp[i][j] = 0; }
    }
    for (int i = 0; i < strlen(S); i++) {
      for (int j = 0; j < strlen(T); j++) {
        if (S[i] == T[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[strlen(S)][strlen(T)] << endl;
  }

  return 0;
}

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

// ---------------------
// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int dp[1010][1010];

int main() {
  int q;
  cin >> q;
  REP(loop, q) {
    char S[1000], T[1000];
    cin >> S >> T;

    REP(i, strlen(S)) {
      REP(j, strlen(T)) { dp[i][j] = 0; }
    }
    for (int i = 0; i < strlen(S); i++) {
      for (int j = 0; j < strlen(T); j++) {
        if (S[i] == T[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[strlen(S)][strlen(T)] << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

string s, t;
int dp[100][100];

void solve() {
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      dp[i][j] =
          (i < 1 || j < 1 ? 0 : dp[i - 1][j - 1]) + (s[i] == t[j] ? 1 : 0);
      int a = (i < 1 ? 0 : dp[i - 1][j]);
      int b = (j < 1 ? 0 : dp[i][j - 1]);
      dp[i][j] = max(dp[i][j], max(a, b));
    }
  }

  cout << dp[s.size() - 1][t.size() - 1] << endl;
}

int main() {
  int n;
  cin >> n;
  while (n--)
    solve();

  return 0;
}

#include <bits/stdc++.h>
using namespace std;

string s, t;
int dp[1000][1000];

void solve() {
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      dp[i][j] =
          (i < 1 || j < 1 ? 0 : dp[i - 1][j - 1]) + (s[i] == t[j] ? 1 : 0);
      int a = (i < 1 ? 0 : dp[i - 1][j]);
      int b = (j < 1 ? 0 : dp[i][j - 1]);
      dp[i][j] = max(dp[i][j], max(a, b));
    }
  }

  cout << dp[s.size() - 1][t.size() - 1] << endl;
}

int main() {
  int n;
  cin >> n;
  while (n--)
    solve();

  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int N, len1, len2;
string seq1, seq2;
int dp[1000][1000];

int main() {
  cin >> N;
  for (int M = 0; M < N; M++) {
    cin >> seq1 >> seq2;
    len1 = seq1.length();
    len2 = seq2.length();
    for (int i = 1; i <= len1; i++) {
      for (int j = 1; j <= len2; j++) {
        if (seq1[i - 1] == seq2[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else if (dp[i][j - 1] > dp[i - 1][j]) {
          dp[i][j] = dp[i][j - 1];
        } else {
          dp[i][j] = dp[i - 1][j];
        }
      }
    }
    cout << dp[len1][len2] << endl;
  }

  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int N, len1, len2;
string seq1, seq2;
int dp[1000 + 10][1000 + 10];

int main() {
  cin >> N;
  for (int M = 0; M < N; M++) {
    cin >> seq1 >> seq2;
    len1 = seq1.length();
    len2 = seq2.length();
    for (int i = 1; i <= len1; i++) {
      for (int j = 1; j <= len2; j++) {
        if (seq1[i - 1] == seq2[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else if (dp[i][j - 1] > dp[i - 1][j]) {
          dp[i][j] = dp[i][j - 1];
        } else {
          dp[i][j] = dp[i - 1][j];
        }
      }
    }
    cout << dp[len1][len2] << endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#define MAX 10000

int lcs(std::string X, std::string Y) {
  int c[MAX][MAX];
  int maxl = 0;
  int m = X.size();
  int n = Y.size();
  for (int i = 1; i <= m; i++) {
    c[i][0] = 0;
  }
  for (int i = 1; i <= n; i++) {
    c[0][i] = 0;
  }
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = std::max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main() {
  std::string s1, s2;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    std::cin >> s1 >> s2;
    int a = lcs(s1, s2);
    printf("%d\\n", lcs(s1, s2));
  }

  return 0;
}

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#define MAX 1000

int lcs(std::string X, std::string Y) {
  int c[MAX + 1][MAX + 1];
  int maxl = 0;
  int m = X.size();
  int n = Y.size();
  for (int i = 1; i <= m; i++) {
    c[i][0] = 0;
  }
  for (int i = 1; i <= n; i++) {
    c[0][i] = 0;
  }
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = std::max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main() {
  std::string s1, s2;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    std::cin >> s1 >> s2;
    int a = lcs(s1, s2);
    printf("%d\\n", lcs(s1, s2));
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main() {
  cin >> n;
  ll ma = 0;
  REP(i, n) {
    string t;
    cin >> s >> t;
    ll c[100][100] = {0};
    ma = 0;
    s = ' ' + s; //????????????????????????
    t = ' ' + t;
    FOR(i, 1, s.size()) { c[i][0] = 0; }
    FOR(i, 1, t.size()) { c[0][i] = 0; }
    FOR(i, 1, s.size()) {
      FOR(j, 1, t.size()) {
        if (s[i] == t[j]) {
          c[i][j] = c[i - 1][j - 1] + 1;
        } else {
          c[i][j] = max(c[i - 1][j], c[i][j - 1]);
        }
        ma = max(ma, c[i][j]);
      }
    }
    cout << ma << Endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll dp[1006][1006] = {0};

int main() {
  cin >> n;
  ll ma = 0;
  REP(i, n) {
    string t;
    cin >> s >> t;
    ma = 0;
    s = ' ' + s; //????????????????????????
    t = ' ' + t;
    FOR(i, 1, s.size()) { dp[i][0] = 0; }
    FOR(i, 1, t.size()) { dp[0][i] = 0; }
    FOR(i, 1, s.size()) {
      FOR(j, 1, t.size()) {
        if (s[i] == t[j]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else {
          dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
        ma = max(ma, dp[i][j]);
      }
    }
    cout << ma << Endl;
  }
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 99999999

#define MAX_S 200
#define MAX_T 200

template <typename T> int lcs(T s, T t) {
  int lens = s.size();
  int lent = t.size();
  int dp[MAX_S + 1][MAX_T + 1] = {};

  rep(i, lens) {
    rep(j, lent) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
    }
  }
  return dp[lens][lent];
}

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    string s, t;
    cin >> s >> t;
    cout << lcs(s, t) << endl;
  }
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 99999999

#define MAX_S 2000
#define MAX_T 2000

template <typename T> int lcs(T s, T t) {
  int lens = s.size();
  int lent = t.size();
  int dp[MAX_S + 1][MAX_T + 1] = {};

  rep(i, lens) {
    rep(j, lent) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
    }
  }
  return dp[lens][lent];
}

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    string s, t;
    cin >> s >> t;
    cout << lcs(s, t) << endl;
  }
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int dp[1010][1010];
int main() {
  int n;
  char x[1001], y[1001];

  // load n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    // load string
    scanf("%s", x);
    scanf("%s", y);
    // dp
    for (int j = 0; j < strlen(x); j++) {
      for (int k = 0; k < strlen(y); k++) {
        if (x[j] == y[k]) {
          dp[j + 1][k + 1] = dp[j][k] + 1;
        }

        else {
          if (dp[j][k + 1] > dp[j + 1][k]) {
            dp[j + 1][k + 1] = dp[j][k + 1];
          }

          else {
            dp[j + 1][k + 1] = dp[j + 1][k];
          }
        }
      }
    }
    cout << dp[strlen(x)][strlen(y)] << endl;
  }

  return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int n;
  char x[1001], y[1001];
  int dp[1010][1010];

  // load n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    // load string
    scanf("%s", x);
    scanf("%s", y);
    // dp
    for (int j = 0; j < strlen(x); j++) {
      for (int k = 0; k < strlen(y); k++) {
        if (x[j] == y[k]) {
          dp[j + 1][k + 1] = dp[j][k] + 1;
        }

        else {
          if (dp[j][k + 1] > dp[j + 1][k]) {
            dp[j + 1][k + 1] = dp[j][k + 1];
          }

          else {
            dp[j + 1][k + 1] = dp[j + 1][k];
          }
        }
      }
    }

    // print
    cout << dp[strlen(x)][strlen(y)] << endl;
  }

  return 0;
}


#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int charCode(char charactor) {
  if (charactor >= 'a' && charactor <= 'z')
    return (int)(charactor - 'a');
  else
    return (int)(charactor - 'A' + 26);
}

bool findSubStr(string &shortword, vector<vector<int>> &charMap) {
  int i, j = 0;
  for (i = 0; i < (int)shortword.size(); ++i) {
    if (charMap[charCode(shortword[i])].empty())
      return false;
    auto itr = charMap[charCode(shortword[i])].begin();
    while (itr != charMap[charCode(shortword[i])].end()) {
      if (*itr < j) {
        ++itr;
      } else {
        break;
      }
    }
    if (itr == charMap[charCode(shortword[i])].end())
      return false;
    j = 1 + *itr;
  }
  return true;
}

int longestSQ(string &shortword, string &longword) {
  int i, j;
  string tempstr, prestr;
  vector<vector<int>> charMap(52);
  queue<string> targetword;
  map<string, bool> inqueue;
  for (i = 0; i < (int)longword.size(); ++i) {
    charMap[charCode(longword[i])].push_back(i);
  }
  targetword.push(shortword);
  while (!targetword.empty()) {
    tempstr = targetword.front();
    if (findSubStr(tempstr, charMap))
      return (int)tempstr.size();
    j = (int)tempstr.size();
    for (i = 0; i < j; ++i) {
      tempstr = targetword.front();
      if (i == 0 || tempstr[i] != tempstr[i - 1]) {
        tempstr.erase(tempstr.begin() + i);
        if (inqueue.find(tempstr) == inqueue.end()) {
          targetword.push(tempstr);
          inqueue[tempstr] = true;
        }
      }
    }
    targetword.pop();
  }
  return 0;
}

int main() {
  int i, q;
  cin >> q;
  string wordA, wordB;
  for (i = 0; i < q; ++i) {
    cin >> wordA >> wordB;
    if (wordA.size() < wordB.size()) {
      printf("%d\\n", longestSQ(wordA, wordB));
    } else {
      printf("%d\\n", longestSQ(wordB, wordA));
    }
  }
  return 0;
}

#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define MAX(a, b) ((a) > (b) ? (a) : (b))

int LCS(string &wordA, string &wordB) {
  int i, j;
  int sizeA, sizeB;
  vector<vector<int>> lcs;
  sizeA = (int)wordA.size();
  sizeB = (int)wordB.size();
  lcs.resize(sizeA + 1);
  lcs[0].resize(sizeB + 1);
  for (i = 0; i <= sizeB; ++i) {
    lcs[0][i] = 0;
  }
  for (i = 1; i <= sizeA; ++i) {
    lcs[i].resize(sizeB + 1);
    lcs[i][0] = 0;
    for (j = 1; j <= sizeB; ++j) {
      if (wordA[i - 1] == wordB[j - 1])
        lcs[i][j] = lcs[i - 1][j - 1] + 1;
      else
        lcs[i][j] = MAX(lcs[i - 1][j], lcs[i][j - 1]);
    }
  }
  return lcs[sizeA][sizeB];
}

int main() {
  int i, j, k, q;
  cin >> q;
  string wordA, wordB;
  for (i = 0; i < q; ++i) {
    cin >> wordA >> wordB;
    cout << LCS(wordA, wordB) << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int lengthOfLcs_r(const char x[], const char y[], int ix, int iy, int xsize,
                  int ysize) {
  if (ix == xsize || iy == ysize) {
    return 0;
  }
  if (x[ix] == y[iy]) {
    return lengthOfLcs_r(x, y, ix + 1, iy + 1, xsize, ysize) + 1;
  }
  return max(lengthOfLcs_r(x, y, ix, iy + 1, xsize, ysize),
             lengthOfLcs_r(x, y, ix + 1, iy, xsize, ysize));
}

int lengthOfLcs(string x, string y) {
  return lengthOfLcs_r(x.c_str(), y.c_str(), 0, 0, x.length(), y.length());
}

int main() {
  int q;
  string x, y;

  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> x >> y;
    cout << lengthOfLcs(x, y) << endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int lengthOfLcs_r(const char x[], const char y[], int ix, int iy, int xsize,
                  int ysize, int **lengthTable) {
  if (ix == xsize || iy == ysize) {
    return 0;
  }
  if (lengthTable[ix][iy] != -1) {
    return lengthTable[ix][iy];
  }
  if (x[ix] == y[iy]) {
    return lengthTable[ix][iy] =
               lengthOfLcs_r(x, y, ix + 1, iy + 1, xsize, ysize, lengthTable) +
               1;
  }
  return lengthTable[ix][iy] =
             max(lengthOfLcs_r(x, y, ix, iy + 1, xsize, ysize, lengthTable),
                 lengthOfLcs_r(x, y, ix + 1, iy, xsize, ysize, lengthTable));
}

int lengthOfLcs(string x, string y) {
  int xsize = x.size(), ysize = y.size();

  int **lengthTable = new int *[xsize];
  for (int i = 0; i < xsize; ++i) {
    lengthTable[i] = new int[ysize];
    fill_n(lengthTable[i], ysize, -1);
  }

  int ret =
      lengthOfLcs_r(x.c_str(), y.c_str(), 0, 0, xsize, ysize, lengthTable);

  for (int i = 0; i < xsize; i++) {
    delete[] lengthTable[i];
  }
  delete[] lengthTable;

  return ret;
}

int main() {
  int q;
  string x, y;

  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> x >> y;
    cout << lengthOfLcs(x, y) << endl;
  }
  return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

const char *X, *Y;

int table_lcs[1001][1001];

int lcs(int x_begin, int y_begin) {
  if (table_lcs[x_begin][y_begin] != -1) {
    return table_lcs[x_begin][y_begin];
  }
  int max = 0;
  for (int i = x_begin; X[i] != '\\0'; i++) {
    for (int j = y_begin; Y[j] != '\\0'; j++) {
      if (X[i] == Y[j]) {
        int v_lcs = lcs(i + 1, j + 1);
        if (v_lcs + 1 > max) {
          max = v_lcs + 1;
        }
      }
    }
  }
  return table_lcs[x_begin][y_begin] = max;
}

int main() {

  int N;
  cin >> N;
  string stringX, stringY;
  for (int i = 1; i <= N; i++) {
    for (int i = 0; i < 1001; i++) {
      for (int j = 0; j < 1001; j++) {
        table_lcs[i][j] = -1;
      }
    }
    cin >> stringX >> stringY;
    X = stringX.c_str();
    Y = stringY.c_str();
    printf("%d\\n", lcs(0, 0));
  }
  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

const char *X, *Y;
int X_length, Y_length;
bool alreadySeenTable[256];
int table_lcs[1001][1001];

int lcs(int x_begin, int y_begin) {
  int i, j, to;
  int max = 0;
  int v_lcs;

  if (table_lcs[x_begin][y_begin] != -1) {
    return table_lcs[x_begin][y_begin];
  }

  for (i = 0; i < 256; i++) {
    alreadySeenTable[i] = false;
  }
  i = x_begin;
  j = y_begin;
  to = Y_length - 1;
  while (i <= X_length - 1) {
    bool found = false;
    while (j <= to) {
      if (X[i] == Y[j]) {
        v_lcs = lcs(i + 1, j + 1) + 1;
        if (v_lcs > max) {
          max = v_lcs;
        }
        found = true;
        break;
      } else {
        j++;
      }
    }
    if (found == false) {
      i++;
      j = y_begin;
    } else {
      i++;
      to = j - 1;
      j = y_begin;
    }
  }
  return table_lcs[x_begin][y_begin] = max;
}

int main() {

  int N;
  cin >> N;
  string stringX, stringY;

  for (int i = 1; i <= N; i++) {
    for (int i = 0; i < 1001; i++) {
      for (int j = 0; j < 1001; j++) {
        table_lcs[i][j] = -1;
      }
    }
    cin >> stringX >> stringY;
    X = stringX.c_str();
    X_length = stringX.size();
    Y = stringY.c_str();
    Y_length = stringY.size();
    printf("%d\\n", lcs(0, 0));
  }
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T> using vv = vector<vector<T>>;

int main() {
  int t;
  cin >> t;
  vi results;
  for (int dataset = 0; dataset < t; dataset++) {
    string a, b;
    cin >> a;
    cin >> b;
    vvi len(a.length() + 1, vi(b.length(), 0));
    for (int ia = 1; ia <= a.length(); ia++) {
      for (int ib = 1; ib <= b.length(); ib++) {
        if (a[ia] == b[ib]) {
          len[ia][ib] = len[ia - 1][ib - 1] + 1;
        } else {
          len[ia][ib] = max(len[ia][ib - 1], len[ia - 1][ib]);
        }
      }
    }
    results.pb(len[a.length()][b.length()]);
  }

  for (int it = 0; it < t; it++) {
    printf("%d\\n", results[it]);
  }

  return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T> using vv = vector<vector<T>>;

int main() {
  int t;
  cin >> t;
  vi results;
  for (int dataset = 0; dataset < t; dataset++) {
    string a, b;
    cin >> a;
    cin >> b;
    vvi len(a.length() + 1, vi(b.length() + 1, 0));
    for (int ia = 0; ia < a.length(); ia++) {
      for (int ib = 0; ib < b.length(); ib++) {
        if (a[ia] == b[ib]) {
          len[ia + 1][ib + 1] = len[ia][ib] + 1;
        } else {
          len[ia + 1][ib + 1] = max(len[ia + 1][ib], len[ia][ib + 1]);
        }
      }
    }
    results.pb(len[a.length()][b.length()]);
  }

  for (int it = 0; it < t; it++) {
    printf("%d\\n", results[it]);
  }

  return 0;
}


// #define		FILE_INPUT_DEFINE
#ifdef FILE_INPUT_DEFINE
#include <fstream>
#endif // FILE_INPUT_DEFINE

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define MAX 1000
#define ind(x) ((x)-1)

int C[MAX][MAX];

int LCS(string &X, string &Y) {
  int Xlen = X.length();
  int Ylen = Y.length();

  for (int i = 0; i <= Xlen; ++i) {
    C[i][0] = 0;
  }

  for (int i = 0; i <= Ylen; ++i) {
    C[0][i] = 0;
  }

  for (int i = 1; i <= Xlen; ++i) {
    for (int j = 1; j <= Ylen; ++j) {
      if (X[ind(i)] == Y[ind(j)]) {
        C[i][j] = C[i - 1][j - 1] + 1;
      } else {
        C[i][j] = max(C[i - 1][j], C[i][j - 1]);
      }
    }
  }

  return (C[Xlen][Ylen]);
}

int main() {
#ifdef FILE_INPUT_DEFINE
  // input from txt
  std::ifstream in(R"(C:\\Temp\\input.txt)");
  std::cin.rdbuf(in.rdbuf());
#endif // FILE_INPUT_DEFINE

  string X, Y;
  int n;

  cin >> n;
  cin.clear();
  cin.ignore();

  for (int i = 0; i < n; ++i) {
    getline(cin, X);
    getline(cin, Y);

    cout << LCS(X, Y) << endl;
  }

  return 0;
}

// #define		FILE_INPUT_DEFINE
#ifdef FILE_INPUT_DEFINE
#include <fstream>
#endif // FILE_INPUT_DEFINE

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define MAX 1000
#define ind(x) ((x)-1)

int C[MAX + 1][MAX + 1];

int LCS(string &X, string &Y) {
  int Xlen = X.length();
  int Ylen = Y.length();

  for (int i = 0; i <= Xlen; ++i) {
    C[i][0] = 0;
  }

  for (int i = 0; i <= Ylen; ++i) {
    C[0][i] = 0;
  }

  for (int i = 1; i <= Xlen; ++i) {
    for (int j = 1; j <= Ylen; ++j) {
      if (X[ind(i)] == Y[ind(j)]) {
        C[i][j] = C[i - 1][j - 1] + 1;
      } else {
        C[i][j] = max(C[i - 1][j], C[i][j - 1]);
      }
    }
  }

  return (C[Xlen][Ylen]);
}

int main() {
#ifdef FILE_INPUT_DEFINE
  // input from txt
  std::ifstream in(R"(C:\\Temp\\input.txt)");
  std::cin.rdbuf(in.rdbuf());
#endif // FILE_INPUT_DEFINE

  string X, Y;
  int n;

  cin >> n;
  cin.clear();
  cin.ignore();

  for (int i = 0; i < n; ++i) {
    getline(cin, X);
    getline(cin, Y);

    cout << LCS(X, Y) << endl;
  }

  return 0;
}


#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#define MAX_N 1000

int solve(std::string s, std::string t) {
  int dp[MAX_N][MAX_N] = {0};
  int n, m;
  n = s.size();
  m = t.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = std::max(dp[i][j + 1], dp[i + 1][j]);
    }
  }
  return dp[n][m];
}

int main() {
  int q;
  std::cin >> q;
  for (int i = 0; i < q; i++) {
    std::string s, t;
    std::cin >> s >> t;
    std::cout << solve(s, t) << std::endl;
  }
  return 0;
}

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#define MAX_N 1001

int solve(std::string s, std::string t) {
  int dp[MAX_N][MAX_N] = {0};
  int n, m;
  n = s.size();
  m = t.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = std::max(dp[i][j + 1], dp[i + 1][j]);
    }
  }
  return dp[n][m];
}

int main() {
  int q;
  std::cin >> q;
  for (int i = 0; i < q; i++) {
    std::string s, t;
    std::cin >> s >> t;
    std::cout << solve(s, t) << std::endl;
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

string a, b;
int lcs_memo[1000][1000];

int lcs(int i, int j) {
  if (i == 0 || j == 0)
    return 0;
  if (lcs_memo[i][j] != -1)
    return lcs_memo[i][j];
  if (a[i] == b[j]) {
    lcs_memo[i][j] = lcs(i - 1, j - 1) + 1;
  } else {
    lcs_memo[i][j] = max(lcs(i, j - 1), lcs(i - 1, j));
  }
  return lcs_memo[i][j];
}

void clear() {
  for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < 1000; j++) {
      lcs_memo[i][j] = -1;
    }
  }
}

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    clear();
    cin >> a >> b;
    a = ' ' + a;
    b = ' ' + b;
    cout << lcs(a.size() - 1, b.size() - 1) << endl;
  }
}

#include <cstdio>
#include <iostream>
#include <string>
#define MAX 1001

using namespace std;

string a, b;
int lcs_memo[1001][1001];

int lcs(int i, int j) {
  if (i == 0 || j == 0)
    return 0;
  if (lcs_memo[i][j] != -1)
    return lcs_memo[i][j];
  if (a[i] == b[j]) {
    lcs_memo[i][j] = lcs(i - 1, j - 1) + 1;
  } else {
    lcs_memo[i][j] = max(lcs(i, j - 1), lcs(i - 1, j));
  }
  return lcs_memo[i][j];
}

void clear() {
  for (int i = 0; i < 1001; i++) {
    for (int j = 0; j < 1001; j++) {
      lcs_memo[i][j] = -1;
    }
  }
}

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    clear();
    cin >> a >> b;
    a = ' ' + a;
    b = ' ' + b;
    cout << lcs(a.size() - 1, b.size() - 1) << endl;
  }
}


#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int lcs(string x, string y);

int main() {
  int n;
  cin >> n;
  string x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    cout << lcs(x, y) << endl;
  }
}

int lcs(string x, string y) {
  int m = x.size(), n = y.size();
  x = ' ' + x;
  y = ' ' + y;
  int **c;
  c = new int *[m + 1];
  for (int i = 0; i <= m; i++)
    c[i] = new int[n + 1];
  for (int i = 0; i <= m; i++)
    c[i][0] = 0;
  for (int j = 0; j <= n; j++)
    c[0][j] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (x[i] == y[j])
        c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      if (i == m && j == n)
        return c[i][j];
    }
  }

  for (int i = 0; i <= m; i++)
    delete[] c[i];
  delete[] c;
}

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int lcs(string x, string y);

int main() {
  int n;
  cin >> n;
  string x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    cout << lcs(x, y) << endl;
  }
  cin.get();
  cin.get();
}

int lcs(string x, string y) {
  int m = x.size(), n = y.size();
  x = ' ' + x;
  y = ' ' + y;
  int **c;
  c = new int *[m + 1];
  for (int i = 0; i <= m; i++)
    c[i] = new int[n + 1];
  for (int i = 0; i <= m; i++)
    c[i][0] = 0;
  for (int j = 0; j <= n; j++)
    c[0][j] = 0;
  int maxl = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (x[i] == y[j])
        c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      maxl = max(maxl, c[i][j]);
    }
  }
  for (int i = 0; i <= m; i++)
    delete[] c[i];
  delete[] c;
  return maxl;
}


#include <bits/stdc++.h>
using namespace std;

int Max(int &a, int b) { return a = max(a, b); }

int LCS(string &a, string &b) {
  int n = a.size();
  int m = b.size();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));

  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) {
      if (i < n && j < m && a[i] == b[j])
        Max(dp[i + 1][j + 1], dp[i][j] + 1);
      Max(dp[i + 1][j], dp[i][j]);
      Max(dp[i][j + 1], dp[i][j]);
    }
  return dp[n][m];
}

int main() {
  int q;
  cin >> q;
  while (q--) {
    string a, b;
    cin >> a >> b;
    cout << LCS(a, b) << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int Max(int &a, int b) { return a = max(a, b); }

int LCS(string &a, string &b) {
  int n = a.size();
  int m = b.size();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));

  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) {
      if (i < n && j < m && a[i] == b[j])
        Max(dp[i + 1][j + 1], dp[i][j] + 1);
      if (i < n)
        Max(dp[i + 1][j], dp[i][j]);
      if (j < m)
        Max(dp[i][j + 1], dp[i][j]);
    }
  return dp[n][m];
}

int main() {
  int q;
  cin >> q;
  while (q--) {
    string a, b;
    cin >> a >> b;
    cout << LCS(a, b) << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int LCS(string p, string q) {
  vector<vector<int>> f(p.size() + 1, vector<int>(q.size() + 1, 0));
  int t;
  for (int i = 1; i <= p.size(); i++) {
    for (int j = 1; j <= q.size(); j++) {
      if (p[i - 1] == q[j - 1])
        f[i][j] = f[i - 1][j - 1] + 1;
      else if (f[i][j - 1] > f[i - 1][j])
        f[i][j] = f[i][j - 1];
      else
        f[i][j] = f[i - 1][j];
    }
  }
  return f[p.size()][q.size()];
}

int main() {
  int n;
  string p[150];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[2 * i] >> p[2 * i + 1];
  }
  for (int i = 0; i < n; i++) {
    cout << LCS(p[2 * i], p[2 * i + 1]) << endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int LCS(string p, string q) {
  vector<vector<int>> f(p.size() + 1, vector<int>(q.size() + 1, 0));
  int t;
  for (int i = 1; i <= p.size(); i++) {
    for (int j = 1; j <= q.size(); j++) {
      if (p[i - 1] == q[j - 1])
        f[i][j] = f[i - 1][j - 1] + 1;
      else if (f[i][j - 1] > f[i - 1][j])
        f[i][j] = f[i][j - 1];
      else
        f[i][j] = f[i - 1][j];
    }
  }
  return f[p.size()][q.size()];
}

int main() {
  int n;
  string p[300];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[2 * i] >> p[2 * i + 1];
  }
  for (int i = 0; i < n; i++) {
    cout << LCS(p[2 * i], p[2 * i + 1]) << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

string str1, str2;

int LCS(int i, int j) {

  if (i == -1 || j == -1) {
    return 0;
  } else if (str1[i] == str2[j]) {
    return LCS(i - 1, j - 1) + 1;
  } else {
    return max(LCS(i - 1, j), LCS(i, j - 1));
  }
}

int main() {
  int N;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> str1 >> str2;
    cout << LCS(str1.size() - 1, str2.size() - 1) << endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

string str1, str2;

int m[1000][1000];

int LCS(int i, int j) {

  if (i == -1 || j == -1) {
    return 0;
  } else if (m[i][j] != 0) {
    return m[i][j];
  } else if (str1[i] == str2[j]) {
    m[i][j] = LCS(i - 1, j - 1) + 1;
    return m[i][j];
  } else {
    m[i][j] = max(LCS(i - 1, j), LCS(i, j - 1));
    return m[i][j];
  }
}

int main() {
  int N;

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> str1 >> str2;
    for (int j = 0; j < 1000; j++) {
      for (int k = 0; k < 1000; k++) {
        m[j][k] = 0;
      }
    }
    cout << LCS(str1.size() - 1, str2.size() - 1) << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>

constexpr int MAX_XY = 1000;

int lx, ly, q, dp[MAX_XY][MAX_XY];
std::string sx, sy;

void fill_dp() {
  for (int i = 1; i <= lx; ++i) {
    for (int j = 1; j <= ly; ++j) {
      if (sx[i - 1] == sy[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
    }
  }
}

void solve() {
  fill_dp();
  std::cout << dp[lx][ly] << std::endl;
  return;
}

int main() {
  std::cin >> q;

  for (int i = 0; i < q; ++i) {
    std::cin >> sx >> sy;
    lx = sx.size(), ly = sy.size();
    solve();
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>

constexpr int MAX_XY = 1010;

int lx, ly, q, dp[MAX_XY][MAX_XY];
std::string sx, sy;

void fill_dp() {
  for (int i = 1; i <= lx; ++i) {
    for (int j = 1; j <= ly; ++j) {
      if (sx[i - 1] == sy[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
    }
  }
}

void solve() {
  fill_dp();
  std::cout << dp[lx][ly] << std::endl;
  return;
}

int main() {
  std::cin >> q;

  for (int i = 0; i < q; ++i) {
    std::cin >> sx >> sy;
    lx = sx.size(), ly = sy.size();
    solve();
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

const int N = 10000;

int lcs(string X, string Y) {
  int c[N + 1][N + 1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) {
    c[i][0] = 0;
  }
  for (int j = 1; j <= n; j++) {
    c[0][j] = 0;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = max(c[i][j - 1], c[i - 1][j]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main() {

  string s1, s2;
  int p;
  cin >> p;
  for (int i = 0; i < p; i++) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

const int N = 1000;
int c[N + 1][N + 1];

int lcs(string X, string Y) {
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) {
    c[i][0] = 0;
  }
  for (int j = 1; j <= n; j++) {
    c[0][j] = 0;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = max(c[i][j - 1], c[i - 1][j]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main() {

  string s1, s2;
  int p;
  cin >> p;
  for (int i = 0; i < p; i++) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  for (int r = 0; r < n; r++) {

    string x, y;
    cin >> x >> y;
    string dp[y.length() + 1][x.length() + 1];

    for (int i = 0; i < y.length(); i++) {
      for (int j = 0; j < x.length(); j++) {
        if (y[i] == x[j]) {
          dp[i + 1][j + 1] = dp[i][j] + y[i];
        } else {
          dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans = max(ans, (int)dp[y.length()][i].length());
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  for (int r = 0; r < n; r++) {

    string x, y;
    cin >> x >> y;
    int dp[y.length() + 1][x.length() + 1];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < y.length(); i++) {
      for (int j = 0; j < x.length(); j++) {
        if (y[i] == x[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]);
        }
      }
    }
    std::cout << dp[y.length()][x.length()] << std::endl;
  }
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <vector>

using namespace std;

const int kMax = 1000 + 10;

int n, m;
char a_str[kMax], b_str[kMax];
int dp[kMax];

vector<int> init_num() {
  vector<int> res;
  map<char, set<int>> table;
  for (int i = 0; i < n; ++i) {
    if (table.count(a_str[i]) > 0)
      table[a_str[i]].insert(i);
    else {
      set<int> s;
      s.insert(i);
      table[a_str[i]] = s;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (table.count(b_str[i]) > 0) {
      for (auto it = table[b_str[i]].rbegin(); it != table[b_str[i]].rend();
           ++it) {
        res.push_back(*it);
      }
    }
  }
  return res;
}

int solve() {
  int res = 1;
  n = strlen(a_str);
  m = strlen(b_str);
  vector<int> num = init_num();
  dp[0] = num[0];
  for (int i = 1; i < num.size(); ++i) {
    if (dp[res - 1] < num[i])
      dp[res++] = num[i];
    else
      dp[lower_bound(dp, dp + res, num[i]) - dp] = num[i];
  }
  return res;
}

int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%s%s", a_str, b_str);
    printf("%d\\n", solve());
  }
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <vector>

using namespace std;

const int kMax = 1000 + 10;

int n, m;
char a_str[kMax], b_str[kMax];
int dp[kMax];

vector<int> init_num() {
  vector<int> res;
  map<char, set<int>> table;
  for (int i = 0; i < n; ++i) {
    if (table.count(a_str[i]) > 0)
      table[a_str[i]].insert(i);
    else {
      set<int> s;
      s.insert(i);
      table[a_str[i]] = s;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (table.count(b_str[i]) > 0) {
      for (auto it = table[b_str[i]].rbegin(); it != table[b_str[i]].rend();
           ++it) {
        res.push_back(*it);
      }
    }
  }
  return res;
}

int solve() {
  n = strlen(a_str);
  m = strlen(b_str);
  vector<int> num = init_num();
  if (num.empty())
    return 0;
  int res = 1;
  dp[0] = num[0];
  for (int i = 1; i < num.size(); ++i) {
    if (dp[res - 1] < num[i])
      dp[res++] = num[i];
    else
      dp[lower_bound(dp, dp + res, num[i]) - dp] = num[i];
  }
  return res;
}

int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%s%s", a_str, b_str);
    printf("%d\\n", solve());
  }
  return 0;
}


#include <algorithm>
#include <functional>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
// #include<utility>
// #include<initializer_list>
// #include<tuple>
// #include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(t) t.begin(), t.end()
bool isSubstring(string substr, string t) {
  int n = substr.length();
  int seek = 0;
  rep(i, n) {
    bool ex = 0;
    for (int j = seek; j < t.length(); j++) {
      if (substr[i] == t[j]) {
        ex = 1;
        seek = j + 1;
        break;
      }
    }
    if (ex) {
      continue;
    } else {
      return false;
    }
  }
  return true;
}

int LongestCommonSubstring(string s, string t) {
  // Wrong plan
  vector<int> dp(s.length(), 0);
  int n = s.length();
  string lcs = "";
  if (isSubstring(s.substr(n - 1, n), t)) {

    dp[n - 1] = 1;
    lcs = s[n - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    // string substr = s.substr(i, n);
    string substr = s[i] + lcs;
    int issubst = isSubstring(substr, t);
    if (issubst)
      lcs = substr;
    dp[i] = dp[i + 1] + issubst;
  }
  return dp[0];
}
int LongestCommonSubstring2(string s, string t) {
  vector<vector<int>> dp(s.length(), vector<int>(t.length(), 0));
  int n = s.length();
  int m = t.length();
  rep(i, n - 1) {
    rep(j, m - 1) {
      dp[i + 1][m + 1] =
          s[i] == t[j] ? dp[i][j] + 1 : max(dp[i][j + 1], dp[i + 1][j]);
    }
  }
  return dp[n - 1][m - 1];
}
int main() {
  // cout << isSubstring("abc", "abcde") << endl;
  // cout << isSubstring("bd", "abcde") << endl;
  // cout << isSubstring("db", "abcde") << endl;

  // cout << LongestCommonSubstring("bacd", "becd") << endl;
  // cout << LongestCommonSubstring("abcd", "becd") << endl;
  // cout << endl;
  // cout << LongestCommonSubstring("a", "a") << endl;
  // cout << LongestCommonSubstring("bbb", "bbb") << endl;
  // cout << LongestCommonSubstring("aba", "bbaba") << endl;
  // cout << LongestCommonSubstring("abababbbaa", "bbabaabba") << endl;
  // cout << LongestCommonSubstring("a", "aaaaa") << endl;
  // cout << LongestCommonSubstring("aizojfeiz", "aaaizojifeizz") << endl;
  // cout << LongestCommonSubstring("zzyiioxizu", "zzsyoizuo") << endl;
  // cout << LongestCommonSubstring("iooooioiooiio", "ooiiioioiooooiioio") <<
  // endl; cout << LongestCommonSubstring("ajfoaooieellzljieoaelj",
  // "ajoiiffoaolliseellzljieoaelj") << endl; cout <<
  // LongestCommonSubstring("zzzzzyyzyy", "zzyyyyz") << endl; cout <<
  // LongestCommonSubstring("abcdef", "fedcba") << endl; cout <<
  // LongestCommonSubstring("abc", "xyz") << endl;
  int q;
  cin >> q;
  vector<string> s(q);
  vector<string> t(q);
  rep(i, q) { cin >> s[i] >> t[i]; }
  rep(i, q) { cout << LongestCommonSubstring2(s[i], t[i]) << endl; }

  return 0;
}

#include <algorithm>
#include <functional>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
// #include<utility>
// #include<initializer_list>
// #include<tuple>
// #include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(t) t.begin(), t.end()
bool isSubstring(string substr, string t) {
  int n = substr.length();
  int seek = 0;
  rep(i, n) {
    bool ex = 0;
    for (int j = seek; j < t.length(); j++) {
      if (substr[i] == t[j]) {
        ex = 1;
        seek = j + 1;
        break;
      }
    }
    if (ex) {
      continue;
    } else {
      return false;
    }
  }
  return true;
}

int LongestCommonSubstring(string s, string t) {
  // Wrong plan
  vector<int> dp(s.length(), 0);
  int n = s.length();
  string lcs = "";
  if (isSubstring(s.substr(n - 1, n), t)) {

    dp[n - 1] = 1;
    lcs = s[n - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    // string substr = s.substr(i, n);
    string substr = s[i] + lcs;
    int issubst = isSubstring(substr, t);
    if (issubst)
      lcs = substr;
    dp[i] = dp[i + 1] + issubst;
  }
  return dp[0];
}
int LongestCommonSubstring2(string s, string t) {
  vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1, 0));
  int n = s.length() + 1;
  int m = t.length() + 1;
  rep(i, n - 1) {
    rep(j, m - 1) {
      dp[i + 1][j + 1] =
          s[i] == t[j] ? dp[i][j] + 1 : max(dp[i][j + 1], dp[i + 1][j]);
    }
  }
  return dp[n - 1][m - 1];
}
int main() {
  // cout << isSubstring("abc", "abcde") << endl;
  // cout << isSubstring("bd", "abcde") << endl;
  // cout << isSubstring("db", "abcde") << endl;

  // cout << LongestCommonSubstring2("bacd", "becd") << endl;
  // cout << LongestCommonSubstring2("abcd", "becd") << endl;
  // cout << endl;
  // cout << LongestCommonSubstring2("a", "a") << endl;
  // cout << LongestCommonSubstring2("bbb", "bbb") << endl;
  // cout << LongestCommonSubstring2("aba", "bbaba") << endl;
  // cout << LongestCommonSubstring2("abababbbaa", "bbabaabba") << endl;
  // cout << LongestCommonSubstring2("a", "aaaaa") << endl;
  // cout << LongestCommonSubstring2("aizojfeiz", "aaaizojifeizz") << endl;
  // cout << LongestCommonSubstring2("zzyiioxizu", "zzsyoizuo") << endl;
  // cout << LongestCommonSubstring2("iooooioiooiio", "ooiiioioiooooiioio") <<
  // endl; cout << LongestCommonSubstring2("ajfoaooieellzljieoaelj",
  // "ajoiiffoaolliseellzljieoaelj") << endl; cout <<
  // LongestCommonSubstring2("zzzzzyyzyy", "zzyyyyz") << endl; cout <<
  // LongestCommonSubstring2("abcdef", "fedcba") << endl; cout <<
  // LongestCommonSubstring2("abc", "xyz") << endl;
  int q;
  cin >> q;
  vector<string> s(q);
  vector<string> t(q);
  rep(i, q) { cin >> s[i] >> t[i]; }
  rep(i, q) { cout << LongestCommonSubstring2(s[i], t[i]) << endl; }

  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pi 3.141592653589793

int solve(string s1, string s2, int l1, int l2) {
  if (l1 == -1 || l2 == -1)
    return 0;
  else if (s1[l1] == s2[l2])
    return solve(s1, s2, l1 - 1, l2 - 1) + 1;
  else
    return max(solve(s1, s2, l1, l2 - 1), solve(s1, s2, l1 - 1, l2));
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    cout << solve(s1, s2, s1.length() - 1, s2.length() - 1) << endl;
  }
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pi 3.141592653589793

int solve(string s1, string s2, int l1, int l2) {
  int a[1001][1001];
  for (int i = 0; i <= l1; i++) {
    a[i][0] = 0;
  }
  for (int i = 0; i <= l2; i++) {
    a[0][i] = 0;
  }
  for (int i = 1; i <= l1; i++) {
    for (int j = 1; j <= l2; j++) {
      if (s1[i - 1] == s2[j - 1])
        a[i][j] = a[i - 1][j - 1] + 1;
      else
        a[i][j] = max(a[i - 1][j], a[i][j - 1]);
    }
  }
  return a[l1][l2];
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    cout << solve(s1, s2, s1.length(), s2.length()) << endl;
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int LCS(string X, string Y) {

  int lcs[X.size() + 1][Y.size() + 1];

  for (int i = 0; i < X.size(); ++i) {
    lcs[0][i] = 0;
  }
  for (int i = 0; i < Y.size(); ++i) {
    lcs[i][0] = 0;
  }

  for (int i = 1; i <= X.size(); ++i) {
    for (int j = 1; j <= Y.size(); ++j) {
      if (X[i - 1] == Y[j - 1]) {
        lcs[i][j] = lcs[i - 1][j - 1] + 1;
      } else if (lcs[i - 1][j] > lcs[i][j - 1]) {
        lcs[i][j] = lcs[i - 1][j];
      } else {
        lcs[i][j] = lcs[i][j - 1];
      }
    }
  }

  return lcs[X.size()][Y.size()];
}

int main() {

  int q;
  scanf("%d", &q);

  for (int i = 0; i < q; ++i) {
    string X, Y;
    cin >> X >> Y;
    cout << LCS(X, Y) << endl;
  }

  return 0;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int LCS(string X, string Y) {

  int m, n;
  m = X.size();
  n = Y.size();

  int c[m + 1][n + 1];

  for (int i = 0; i <= m; ++i) {
    c[i][0] = 0;
  }
  for (int i = 0; i <= n; ++i) {
    c[0][i] = 0;
  }

  X = ' ' + X;
  Y = ' ' + Y;

  int maxl = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return maxl;
}

int main() {

  int q;
  scanf("%d", &q);

  for (int i = 0; i < q; ++i) {
    string X, Y;
    cin >> X >> Y;
    cout << LCS(X, Y) << endl;
  }

  return 0;
}