Go: package main

import (
	"bufio"
	"os"
	"io"
	"strconv"
	"math"
	"fmt"
)

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()

	n := nint()
	xList := make([]string, n)
	yList := make([]string, n)

	for i:=0;i<n ;i++  {
		xList[i] = nstr()
		yList[i] = nstr()
	}

	for i := 0; i<n	; i++  {
		fmt.Println(lcs(xList[i], yList[i]))
	}

}

func lcs(x string, y string) int{
	var m = len(x)
	var n = len(y)

	c := make([][]int, m+1)
	for i:= range c{
		c[i] = make([]int, n+1)
	}
	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] = int(math.Max(float64(c[i-1][j]), float64(c[i][j-1])))
			}


		}
	}
	return c[m][n]

}


func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define len_max 1000


string X;
string Y;
int dp[len_max+1][len_max+1];

int lcs(){
    int m = X.length();
    int n = Y.length();

    X = ' ' + X;//ずらす
    Y = ' ' + Y;
    

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

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

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(Y[i] == X[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[n][m];

}


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

    int ans[q];

    for(int i = 0; i < q; i++){
        cin >> X >> Y;
        //printf("%d\n", lcs());
        ans[i] = lcs();
    }

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

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int MAXL = 1e3+7;
char s1[MAXL];
char s2[MAXL];
int dp[MAXL][MAXL];
int maxLCS(char s1[], char s2[]){
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    int i;
    for(i = 0; i <= l1; i++){
        dp[0][i] = 0;
    }
    for(i = 0; i <= l2; i++){
        dp[i][0] = 0;
    }
    int j;
    for(i = 1; i <= l2; i++){
        for(j = 1; j <= l1; j++){
            int max_k = max(dp[i-1][j], dp[i][j-1]);
            if(s1[j-1] == s2[i-1]) max_k = max(max_k, dp[i-1][j-1]+1);
            else max_k = max(max_k, dp[i-1][j-1]);
            dp[i][j]= max_k;
        }
    }
    return dp[l2][l1];
}
int main(){
//    freopen(".../in.txt", "r", stdin);
    int q;
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%s", s1);
        scanf("%s", s2);
        int q = maxLCS(s1, s2);
        printf("%d\n", q);
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>

#define MAX_LENGTH 1000
#define NIL -1
using namespace std;
//think easy make easy

int q;//num of datasets
string X;
string Y;
char map[MAX_LENGTH+1][MAX_LENGTH+1];

int findMaxLength(int x,int y){//x:Xの終端.y:Yの終端(0オリジン)
	int val;

	if(x < 0 || y < 0) return 0;

	if(map[x][y] == NIL){
		if(X.at(x) == Y.at(y)){
			val = findMaxLength(x-1,y-1) +1;
		}else{
			val = max(findMaxLength(x-1,y),findMaxLength(x,y-1));
		}
		map[x][y] = val;//メモ
		return val;
	}else return map[x][y];
}

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

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

	return 0;
}

C++: #include <algorithm>
#include<iostream>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;
int dp[1001][1001];
int lcs(string x,string y){
  int m,n;
  lll ii,jj,kk;
  
  m = x.size();
  n = y.size();
  memset(dp,0,sizeof(dp));
  int maxl = 0;

  for(ii=0;ii<m;ii++){
    for(jj=0;jj<n;jj++){
      if(x[ii] == y[jj]){
        dp[ii+1][jj+1] = dp[ii][jj] + 1;
      }
      else{
        dp[ii+1][jj+1] = max(dp[ii][jj+1],dp[ii+1][jj]);
      }

      maxl = max(maxl,dp[ii+1][jj+1]);
      
    }
  }
  return maxl;
}

int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int q;
  string x,y;

  cin >> q;

  for(ii=0;ii<q;ii++){
    cin >> x >> y;
    cout << lcs(x,y) << endl;
  }

  return 0;
}

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

static const int N = 100;

int main() {
  int n, p[N + 1], m[N + 1][N + 1];
  cin >> n;
  for ( int i = 1; i <= n; i++ ) {
    cin >> p[i - 1] >> p[i];
  }

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

  for ( int l = 2; l <= n; l++ ) {
    for ( int i = 1; i <= n - l + 1; i++ ) {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      for ( int k = i; k <= j - 1; k++ ) {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;
}

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

int preX[1020][55];
int dp[1020];

int main() {
	int q;
	cin >> q;
	for(int t = 0; t < q; t++) {
		string X, Y;
		for(int i = 0; i < 1020; i++) {
			for(int j = 0; j < 55; j++) {
				preX[i][j] = 0;
			}
			dp[i] = 0;
		}
		cin >> X >> Y;
		for(int i = 0; i < X.size(); i++) {
			for(int j = 0; j < 55; j++) {
				preX[i+1][j] = preX[i][j];
			}
			if(i > 0) {
				if('a' <= X[i-1] && X[i-1] <= 'z')
					preX[i+1][X[i-1]-'a'] = i;
				else
					preX[i+1][X[i-1]-'A'] = i;
			}
		}
		for(int i = 0; i < Y.size(); i++) {
			for(int j = (int)X.size()-1; j >= 0; j--) {
				if(Y[i] == X[j])
					for(int k = 0; k < 55; k++)
						dp[j+1] = max(dp[j+1], dp[preX[j+1][k]] + 1);
			}
		}
		int res = 0;
		for(int i = 0; i < 1020; i++)
			res = max(res, dp[i]);
		cout << res << endl;
	}
}

C++: //compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
int solve(string x, string y){
	int xl = x.length() - 1;
	int yl = y.length() - 1;
	int dp[1250][1250];
		for(int i=0;i<=xl;i++) dp[i][0] = 0;
		for(int i=1;i<=yl;i++) dp[0][i] = 0;
	if(x == y) return max(xl, yl);
	for(int i=1;i<=xl;i++){
		for(int j=1;j<=yl;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[xl][yl];
}

int main(){
	int q;
	string x, y;
	int i;
	cin >> q;
	rep(i, q){
		cin >> x >> y;
		cout << solve(x = " " + x, y = " " + y) <<endl;
	}


}