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 <bits/stdc++.h>
using namespace std;

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

  vector<int> anss;
  for (int i = 0; i < n; i++)
  {
    string s,t;
    cin >> s >> t;

    int lens = s.size();
    int lent = t.size();
    int dp[lens][lent];
    bool flg = false;
    for (int j = 0; j < lens; j++)
    {
      if(t[0]==s[j]) flg = true;
      if(flg) dp[j][0] = 1;
      else dp[j][0] = 0;
    }
    flg = false;
    for (int j = 0; j < lent; j++)
    {
      if(s[0]==t[j]) flg = true;
      if(flg) dp[0][j] = 1;
      else dp[0][j] = 0;
    }

    for (int j = 1; j < lens; j++)
    {
      for (int k = 1; k < lent; k++)
      {
        if(s[j]==t[k]) dp[j][k] = dp[j-1][k-1]+1;
        else dp[j][k] = max(dp[j-1][k],dp[j][k-1]);
      }      
    }
    anss.push_back(dp[lens-1][lent-1]);
  }
  for(int ans:anss) cout << ans << endl;
}

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

int main() {
  int q; cin >> q;
  string A, B;
  for (int i=0; i<q; i++) {
    cin >> A >> B;
    vector<vector<int>> LCS(A.length()+1, vector<int>(B.length()+1,0));
    int ans=0;
    for (int j=1; j<=A.length(); j++) {
      for (int k=1; k<=B.length(); k++) {
        if(A[j]==B[k]) LCS[j][k]=LCS[j-1][k-1]+1;
        else LCS[j][k]=max(LCS[j-1][k],LCS[j][k-1]);
        ans = max(ans, LCS[j][k]);
      }
    }
    cout << ans << "\n";
  }
}

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++ ) {
    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 q;
  cin >> q;

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

  return 0;
}

C++: #include <stdio.h>

int judge(char A[], char B[]){
  int a=0, b=0, sw=0, ans=0;
  int i, j;
  int C[1001][1001];
  
  while(sw == 0){
    if(A[a] != EOF)
      a++;
    else
      sw = 1;
  }
  
  sw = 0;
  
  while(sw == 0){
    if(B[b] != EOF)
      b++;
    else
      sw = 1;
  }
  
  for(i=1; i<a+1; i++)
    C[i][0] = 0;
  for(i=1; i<b+1; i++)
    C[0][i] = 0;
  
  for(i=1; i<a+1; i++){
    for(j=1; j<b+1; j++){
      if(A[i-1] == B[j-1])
        C[i][j] = C[i-1][j-1] + 1;
      else if(C[i-1][j] >= C[i][j-1])
        C[i][j] = C[i-1][j];
      else
        C[i][j] = C[i][j-1];
      if(ans < C[i][j])
        ans = C[i][j];
    }
  }
  
  return ans;
}

int main(){
  char A[1000], B[1000];
  int n, i;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%s", A);
    scanf("%s", B);
    printf("%d\n", judge(A, B));
  }
  
  return 0;
}

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

using namespace std;

int main() {
	int n;	
	int c[1001][1001];
	string str1, str2;

	cin >> n;

	for (int k = 0; k < n; k++) {
		int Max = 0;
		cin >> str1 >> str2;
		
		int m = str1.size();
		int n = str2.size();


		str1 = ' ' + str1;
		str2 = ' ' + str2;

		//cout << str1 << str2 << endl;


		for (int i = 0; i <= m; i++) {
			for (int j = 0; j <= n; j++) {
				if (i == 0 || j == 0) c[i][j] = 0;
				else if (str1[i] == str2[j]) c[i][j] = c[i - 1][j - 1] + 1;
				else c[i][j] = max(c[i][j - 1], c[i - 1][j]);

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

				//cout << c[i][j] << " ";

			}

			//cout << endl;

		}

		cout << Max << endl;
	}

	return 0;

}

C++: #include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int dp[1010][1010];
string x, y;

int solve(int a, int b) {
    if (dp[a][b] >= 0) {
        return dp[a][b];
    }
    
    if (a * b == 0) {
        dp[a][b] = 0;
        return 0;
    }
    
    if (char(x[a - 1]) == char(y[b - 1])) dp[a][b] = solve(a - 1, b - 1) + 1;
    else dp[a][b] = solve(a - 1, b - 1);
    
    dp[a][b] = max(dp[a][b], max(solve(a - 1, b), solve(a, b - 1)));
    
    return dp[a][b];
}

int main(void){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        
        for (int i = 0; i <= x.size(); i++) {
            for (int j = 0; j <= y.size(); j++) dp[i][j] = -1;
        }
        dp[0][0] = 0;
        
        cout << solve(x.size(), y.size()) << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespase 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 = 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 ( i = 0; i < n; i++ ){
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << sndl;
    }
    
    return 0;
    
}