Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

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

using namespace std;

int N=1000;

int LCS(string x,string y){
	int c[N+1][N+1],LCSlen=0;
	int m=x.size();
	int n=y.size();
	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][j-1],c[i-1][j]);
			LCSlen=max(LCSlen,c[i][j]);
		}
	}
	return LCSlen;
}

int main(){
	char x[1000],y[1000];
	string xst,yst;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",x);
		scanf("%s",y);
		xst=x;
		yst=y;
		printf("%d\n",LCS(x,y));
	}
}

C++: #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;

int main() {
  int t;
  cin >> t;
  vi results;
  for (int dataset = 0 ; dataset < t ; dataset++) {
    string a, b;
    cin >> a;
    cin >> b;
    vvi len(a.length()+1, vi(b.length(), 0));
    for (int ia = 1 ; ia <= a.length() ; ia++) {
      for (int ib = 1 ; ib <= b.length() ; ib++) {
        if (a[ia] == b[ib]) {
          len[ia][ib] = len[ia-1][ib-1]+1;
        } else {
          len[ia][ib] = max(len[ia][ib-1], len[ia-1][ib]);
        }
      }
    }
    results.pb(len[a.length()][b.length()]);
  }

  for (int it = 0 ; it < t ; it++) {
    printf("%d\n", results[it]);
  }

  return 0;
}

C++: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

long long int INF = 1e18;
using namespace std;

typedef pair<long long int, long long int> P;

long long int DP[1001][1001] = {};

int main(){
	
	int n;
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		
		string str1, str2;
		cin >> str1 >> str2;
		
		for(int i = 1; i <= str1.size(); i++){
			for(int j = 1; j <= str2.size(); j++){
				if(str1[i - 1] == str2[j - 1]){
					DP[i][j] = max(max(DP[i - 1][j - 1] + 1, DP[i - 1][j]), DP[i][j - 1]);
				}else{
					DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
				}
			}
		}
		
		cout << DP[str1.size()][str2.size()] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;


long long L[1010][1010] {0};
int main(){
  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++){
    string X, Y;
    cin >> X >> Y;
    int xlen = X.length();
    int ylen = Y.length();
    for(int i = 1; i<= xlen; i++){
      for(int k = 1; k <= ylen; k++){
	if(X[i-1] == Y[k-1]){
	  L[i][k] = 1 + L[i-1][k-1];
	}else{
	  L[i][k] = max(L[i][k-1], L[i-1][k]);
	}
      }
    }

    cout << L[xlen][ylen] << endl;
  }

}

C++: #include <iostream>
#include <string>
using namespace	std;
int main(){

  int n;
  string s1,s2;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s1>>s2;
    int dp[1001][1001]={};
    for(int j=1;j<=s2.size();j++){
      for(int k=1;k<=s1.size();k++){
        if(s1[k-1]==s2[j-1]) dp[j][k]=dp[j-1][k-1]+1;
        else dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
      }
    }
    cout<<dp[s2.size()][s1.size()]<<endl;
  }
  return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1005;
int main() {
	int n; cin >> n;
	vv(int, dp, MAX, MAX, 0);
	string X, Y;
	rep(i, 0, n) {
		cin >> X >> Y;
		int len_X = len(X);
		int len_Y = len(Y);
		rep(i, 0, len_X) {
			rep(j, 0, len_Y) {
				dp[i + 1][j + 1] = (X[i] == Y[j] ? dp[i][j] + 1 : max(dp[i][j + 1], dp[i + 1][j]));
			}
		}
		P(dp[len_X][len_Y]);
	}
	return 0;
}

C++: #include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 998244353 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//ld dis(ll a,ll b,ll c,ll d){return sqrt((a-c)*(a-c)+(b-d)*(b-d)) ;}

void chmax(ll &a,ll b){a = max(a,b) ;}

int main(){
	ll q ; cin >> q ;
	for(int tt=0;tt<q;tt++){
		string s,t ;
		cin >> s >> t ;
		vvll dp(s.size()+1,vll(t.size()+1,0)) ;
		for(int i=1;i<=s.size();i++){
			for(int j=1;j<=t.size();j++){
				chmax(dp.at(i).at(j),dp.at(i-1).at(j)) ;
				chmax(dp.at(i).at(j),dp.at(i).at(j-1)) ;
				if(s.at(i-1)==t.at(j-1)) chmax(dp.at(i).at(j),dp.at(i-1).at(j-1)+1) ;
			}
		}
		cout << dp.at(s.size()).at(t.size()) << endl ;
	}
}

C++: #include <iostream>
#include <string>

using namespace std;

int solve(string s1, string s2){
    int L[s1.size()][s2.size()];
    for(int i=0;i<s1.size();i++){
        for(int j=0;j<s2.size();j++){
            if(i==0 || j==0){
                if(s1[i] == s2[j])
                    L[i][j] = 1;
                else
                    L[i][j]=0;
            }
            else if(s1[i] == s2[j]){
                L[i][j] = 1 + L[i-1][j-1];
            }
            else{
                L[i][j] = max(L[i][j-1],L[i-1][j]);
            }
        }
    }
    return L[s1.size()-1][s2.size()-1];
}

int main(){
    int n ; cin >> n;
    for(int i=0;i<n;i++){
        string s1,s2; cin>> s1 >> s2;\
        cout << solve(s1,s2) << endl;
    }
}