Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 1001

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func lcs(x, y string) int {
	var c [N][N]int
	m := len(x)
	n := len(y)
	var maxl int

	x = " " + x
	y = " " + y

	for i := 1; i <= m; i++ {
		for 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
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	var out bytes.Buffer
	for i := 0; i < q; i++ {
		sc.Scan()
		s1 := sc.Text()
		sc.Scan()
		s2 := sc.Text()
		out.WriteString(fmt.Sprintf("%d\n", lcs(s1, s2)))
	}
	return strings.TrimRight(out.String(), "\n")
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include <iostream>
#include <vector>
using namespace  std;

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();
    vector<vector<int>> vvnLcsDP(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

C++: // ????????±?????¨??????
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <set>
#include <string>
#define MAX 1050
using namespace std;
int q,length_x,length_y;
int dp[MAX][MAX];
string X,Y;
int init_func () {
  for (int i=0; i<MAX ; i++)
    for (int j=0; j<MAX ; j++)
      dp[i][j] = 0;
}

int solve () {
  // dp = {0}
  // dp?????¨?????????X????¨????Y??¨??????
  for (int tate=1; tate<=length_x ; tate++)
    for (int yoko=1; yoko<=length_y ; yoko++)
      if (X[tate-1] == Y[yoko-1]) dp[tate][yoko] = 1 + dp[tate-1][yoko-1];
      else dp[tate][yoko] = max(dp[tate-1][yoko],dp[tate][yoko-1]);
  
  return dp[length_x][length_y];
}

int main(){
  cin >> q;
  for (int i=0; i<q; i++) {
    cin >> X >> Y;
    length_x = X.length();
    length_y = Y.length();
    init_func();
    cout << solve() << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int lcs (string x, string y) {

    int m, n, c[1001][1001], i, j, maxl = 0;

    m = x.size();
    n = y.size();

    x = ' ' + x;
    y= ' ' + y;

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

    for (i = 1; i <= m; i++) {
            for (j = 1; j <= n; j++) {

                if (x[i - 1] == y[j - 1]) {
                    c[i][j] = c[i - 1][j - 1] + 1;
                } else {
                    c[i][j] = max (c[i - 1][j], c[i][j - 1]);
                }

                maxl = max (max, c[i][j]);

            }
    }

    return maxl;

}



int main () {

    int N, i;
    string x, y;

    cin >> N;

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

    }

    return 0;

}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N =1000;
int lcs(string, 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++){
    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] = mx(c[i - 1][j], c[i][j = 1]);
      }
      maxl = max(mxl, 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 << lcs8s1, s2) << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>

using namespace std;

static const int N = 1000;

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

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;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int lcs(string X, string Y){
  int c[1001][1001];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = " " + X;
  Y = " " + Y;
  for(int i = 0;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-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;
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int N, M;
string s1, s2;

int lcs(string x, string y){
	int c[1001][1001];
	N = s1.size();
	M = s2.size();
	int maxl = 0;
	x = ' ' + x;
	y = ' ' + y;
	rep(i, N) c[i][0] = 0;
	rep(i, M) c[0][i] = 0;
	for(int i = 1; i<=N;i++){
		for(int j = 1; j<=M; 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(){
	int n;
	cin >> n;
	rep(i, n){
		cin >> s1 >> s2;
		cout << lcs(s1,s2) << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;

static const int N = 1000;

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 - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }

    return maxl;
}

int main(int argc, char const* argv[])
{
    string s1, s2;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}