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
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll Q;cin>>Q;
    REP(i,Q){
        string s1,s2;cin>>s1>>s2;
        ll n1=s1.size(),n2=s2.size();
        ll dp[n1+1][n2+1]={};
        REPS(i,n1){
            REPS(j,n2){
                if(s1[i-1]==s2[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[n1][n2]<<"\n";
    }
}

C++: n=int(input())
ans=[]
for k in range(n):
    s1=input()
    s2=input()
    dp=[[0 for i in range(len(s2)+1)] for j in range(len(s1)+1)]
    for i in range(1,len(s1)+1):
        for j in range(1,len(s2)+1):
            if s1[i-1]==s2[j-1]:
                dp[i][j]=dp[i-1][j-1]+1
            else:
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])


    ans.append(dp[len(s1)][len(s2)])
for a in ans:
    print(a)

C++: #include<iostream>
#include<string>
using namespace std;
int alignment(string s,string t){


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

int main(void){

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

		string s;
		string t;
		cin >> s >> t;
		cout << alignment(s,t) <<endl;
	}
	
}

C++: #include <iostream>
#include <string>
using namespace std;
const int LEN = 1005;
string X,Y;
int dp[LEN][LEN];

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i)
	{
		cin >> X >> Y;

		int xn = X.size();
		int yn = Y.size();

		for (int j = 0; j <= xn; ++j)
		{
			dp[j][0] = 0;
		}

		for (int j = 0; j <= yn; ++j)
		{
			dp[0][j] = 0;
		}

		for (int j = 0; j < xn; ++j)
		{
			for (int k = 0; k < yn; ++k)
			{
				if (X[j] == Y[k])
				{
					dp[j+1][k+1] = max(dp[j][k]+1, max(dp[j][k+1], dp[j+1][k]));
				}
				else
				{
					dp[j+1][k+1] = max(dp[j][k+1], dp[j+1][k]);
				}
			}
		}

		cout << dp[xn][yn] << endl;
	}

	
	return 0;
}

C++: #include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const long long mod=1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dp[1005][1005];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);    
int q=0;
cin>>q;
vector<vector<string>> s(q,vector<string>(2));
for(int i=0;i<q;i++)cin>>s.at(i).at(0)>>s.at(i).at(1);
for(int pos=0;pos<q;pos++){
    memset(dp,0,sizeof(dp));
    string a=s.at(pos).at(0),b=s.at(pos).at(1);
    for(int i=0;i<(int)a.size();i++){
        for(int j=0;j<(int)b.size();j++){
            if(a.at(i)==b.at(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[a.size()][b.size()]<<endl;
}

}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int q;
  cin >> q;
  REP(i, q) {
    string X, Y;
    cin >> X >> Y;
    vector<vector<int>> dp(Y.size() + 5, vector<int>(X.size() + 5, 0));
    for (int i = 0; i < Y.size(); i++) {
      for (int j = 0; j < X.size(); j++) {
        if (Y[i] == X[j]) {
          chmax(dp[i + 1][j + 1], dp[i][j] + 1);
          chmax(dp[i + 1][j + 1], dp[i][j + 1]);
          chmax(dp[i + 1][j + 1], dp[i + 1][j]);
        } else {
          chmax(dp[i + 1][j + 1], dp[i][j + 1]);
          chmax(dp[i + 1][j + 1], dp[i + 1][j]);
        }
      }
    }
    cout << dp[Y.size()][X.size()] << 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(){
 
string s1,s2;
int n;cin >> n;
for(int i=0;i<n;i++){
cin >> s1 >> s2;
cout << lcs(s1,s2) << endl;
}
return 0;
 
}