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++: #pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int q; cin >> q;

    REP(_, q) {
        string x, y; cin >> x >> y;

        vector<vi> dp(x.size() + 1, vi(y.size() + 1, 0));

        REP(i, x.size()) REP(j, y.size()) {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + int(x[i] == y[j]));
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j+1]);
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i+1][j]);
        }

        print(dp[x.size()][y.size()]);
    }

}

C++: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//BEGIN CUT HERE
int lcs(string s,string t){
  int n=s.size(),m=t.size();
  s+='$';t+='%';
  vector<vector<int> > dp(n+2,vector<int>(m+2,-(n+m)));
  dp[0][0]=0;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      chmax(dp[i+1][j],dp[i][j]);
      chmax(dp[i][j+1],dp[i][j]);
      chmax(dp[i+1][j+1],dp[i][j]+(s[i]==t[j]));
    }
  }
  return dp[n][m];
}
//END CUT HERE

//INSERT ABOVE HERE
signed ALDS1_10_C(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int q;
  cin>>q;
  while(q--){
    string s,t;
    cin>>s>>t;
    cout<<lcs(s,t)<<"\n";
  }
  cout<<flush;
  return 0;
}
/*
  verified on 2019/04/07
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp
*/

signed main(){
  ALDS1_10_C();
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 1005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int dp[SIZE][SIZE];

void solve(){
  int n,m;
  string X,Y;
  cin >> X >> Y;
  n = X.size();
  m = Y.size();
  fill(dp[0],dp[0]+SIZE,0);
  rep(i,0,n) rep(j,0,m){
    int a=0,b=0,c=0;
    if(i>0)a = dp[i-1][j];
    if(j>0)b = dp[i][j-1];
    if(i>0 && j>0)c = dp[i-1][j-1];
    dp[i][j] = max({a,b,c+(X[i]==Y[j]?1:0)});
  }
  cout << dp[n-1][m-1] << endl;
}

int main(){

  int q;
  cin >> q;
  rep(i,0,q){
    solve();
  }

  return 0;
}

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

int dp[1001][1001];
int q;

void solve(){
  char x[1001],y[1001];
  scanf("%s %s",x,y);
  int lx = strlen(x);
  int ly = strlen(y);
  for(int i=0;i<=lx;i++){
    for(int j=0;j<=ly;j++){
      if(i==0||j==0) dp[i][j] = 0;
      else if(x[i]==y[j]) dp[i][j] = dp[i-1][j-1]+1;
      else dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
    }
  }
  printf("%d\n",dp[lx][ly]);
  return;
}


int main(){
  scanf("%d",&q);
  for(int i=0;i<q;i++) solve();
  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();
  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 <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int lcs(string s1, string s2) {
    int i, j, ret = 0;
    int n = s1.size();
    int m = s2.size();
    int c[n+1][m+1];
    s1 = ' ' + s1;
    s2 = ' ' + s2;

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

    for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
            if (s1[i] == s2[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            ret = max(ret, c[i][j]);
        }
    }
    
    return ret;
}

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

    return 0;
}