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 <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 150
void solve(void);
int q,count[MAX][MAX]={},xlength,ylength;
char X[MAX],Y[MAX];

void solve(void){
  int i,j;

  xlength=strlen(X);
  ylength=strlen(Y);
  
  for(i=1;i<=strlen(X);i++){
    for(j=1;j<=strlen(Y);j++){
      if(X[i-1]==Y[j-1]) count[i][j]=count[i-1][j-1]+1;
      else if(count[i-1][j]>=count[i][j-1]) count[i][j]=count[i-1][j];
      else count[i][j]=count[i][j-1];
    }
  }

}
    

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

  for(i=1;i<=q;i++){
    scanf("%s",X);
    scanf("%s",Y);
    solve();
    printf("%d\n",count[xlength][ylength]);
  }

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

  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int q;
int main(){
  cin>>q;
  for(int z=0;z<q;z++){
    string a,b;
    cin>>a>>b;
    int n=a.size(),m=b.size();
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
        if(a[i]==b[j]){
          dp[i+1][j+1]=dp[i][j]+1;
        }else{
          dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
        }
      }
    }
    cout<<dp[n][m]<<endl;
  }
}

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

int main(){
    int N;
    cin>>N;
    int ans[151];
    if(N>20){
        for(int i=0;i<N;i++){
            string inp1,inp2;
            cin>>inp1;
            cin>>inp2;
            int dp[101][101]={};
            for(int j=1;j<=inp1.size();j++){
                for(int k=1;k<=inp2.size();k++){
                    if(inp1[j]==inp2[k]){
                        dp[j][k]=dp[j-1][k-1]+1;
                    }else{
                        dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
                    }
                }
            }
            ans[i]=dp[inp1.size()][inp2.size()];
        }
    }else{
        for(int i=0;i<N;i++){
            string inp1,inp2;
            cin>>inp1;
            cin>>inp2;
            int dp[1001][1001]={};
            for(int j=1;j<=inp1.size();j++){
                for(int k=1;k<=inp2.size();k++){
                    if(inp1[j]==inp2[k]){
                        dp[j][k]=dp[j-1][k-1]+1;
                    }else{
                        dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
                    }
                }
            }
            ans[i]=dp[inp1.size()][inp2.size()];
        }
    }
    for(int i=0;i<N;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vi> dp(n+2, vi(m+2));
    rep(i, n+1) rep(j, m+1) {
        // cout << i << " " << j << endl;
        if(i >= n) {
            chmax(dp[i][j+1], dp[i][j]);
        }
        else if(j >= m) {
            chmax(dp[i+1][j], dp[i][j]);
        }
        else if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
        else {
            chmax(dp[i+1][j], dp[i][j]);
            chmax(dp[i][j+1], dp[i][j]);
        }
    }
    cout << dp[n][m] << '\n';
    // rep(i, n+2) {
    //     rep(j, m+2) {
    //         cout << " " << dp[i][j];
    //     }
    //     cout << endl;
    // }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, n) solve();
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int dp[1005][1005] = { 0 };
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string x, y;
		cin >> x >> y;
		for (int j = 0; j < 1005; j++)
			for (int k = 0; k < 1005; k++) dp[j][k] = 0;
		for (int j = 1; j <= x.size(); j++) {
			for (int k = 1; k <= y.size(); k++) {
				dp[j][k] = max(dp[j][k - 1], dp[j - 1][k]);
				if (x[j - 1] == y[k - 1]) {
					dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + 1);
				}
			}
		}
		cout << dp[x.size()][y.size()] << endl;
	}
	return 0;
}