Go: package main

import "fmt"

func main() {
	var nPairs int
	fmt.Scanln(&nPairs)

	var a, b string
	for i := 0; i < nPairs; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Println(lcsSize(a, b))
	}
}

func lcsSize(sa, sb string) int {
	dp := make([][]int, len(sa)+1)
	for i := 0; i <= len(sa); i++ {
		dp[i] = make([]int, len(sb)+1)
	}

	for a := 1; a <= len(sa); a++ {
		for b := 1; b <= len(sb); b++ {
			if sa[a-1] == sb[b-1] {
				dp[a][b] = dp[a-1][b-1] + 1
			} else {
				dp[a][b] = max(dp[a][b-1], dp[a-1][b])
			}
		}
	}

	return dp[len(sa)][len(sb)]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

int Longest(string x, string y) {
  int L[1001][1001];
  int maxl = -1;
  int xlen = x.size();
  int ylen = y.size();

  x = ' ' + x;
  y = ' ' + y;

  for (int i = 1; i <= xlen; i++) L[i][0] = 0;
  for (int j = 1; j <= ylen; j++) L[0][j] = 0;

  for (int i = 1; i <= xlen; i++) {
    for (int j = 1; j <= ylen; j++) {
      if (x[i] == y[j])
        L[i][j] = L[i-1][j-1] + 1;
      else
        L[i][j] = max(L[i][j-1], L[i-1][j]);

      maxl = max(maxl, L[i][j]);
    }
  }

  return maxl;
}

int main() {
  string X, Y;
  int n;
  int result[10000];

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> X;
    cin >> Y;
    result[i] =  Longest(X, Y);
    cout << result[i] << endl;
  }

  


  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int q=0;q<n;q++){
        string s,t;
        cin>>s>>t;
        int ss=s.length(),ts=t.length();
        int dp[ss+5][ts+5];
        for(int i=0;i<ss+5;i++){
            for(int j=0;j<ts+5;j++)dp[i][j]=0;
        }
        for(int i=0;i<ss;i++){
            for(int j=0;j<ts;j++){
                if(s[i]==t[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[ss][ts]<<endl;
    }
}

C++: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int q, n, m, dp[1007][1007]; string s, t;
int main() {
	cin >> q;
	while(q--) {
		cin >> s >> t;
		n = s.size(), m = t.size();
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				dp[i][j] = (s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]));
			}
		}
		cout << dp[n][m] << endl;
	}
}

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

#define MAX 1000

using namespace std;


int m[MAX + 2][MAX + 2];
int lcs(string x, string y)
{
    for (int i = 0; i <= y.length(); i++)
        for (int j = 0; j <= x.length(); j++)
            m[i][j] = 0;

    for (int i = 1; i <= y.length(); i++) {
        for (int j = 1; j <= x.length(); j++) {
            if (x[j - 1] == y[i - 1]) {
                m[i][j] = m[i - 1][j - 1] + 1;
            } else {
                m[i][j] = max(m[i - 1][j], m[i][j - 1]);
            }
        }
    }

    return m[y.length()][x.length()];
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string x, y;
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#define MAX 1000000000000000000LL
long long inf=1000000007;
using namespace std;
    int H,A[2000001];

int lcs(string X,string Y){
    int  c[1001][1001];
    long long m=X.size();
    long long  n=Y.size();
    int maxl=0;
    X=' '+X;
    Y=' '+Y;
    for(int i=1; i<=m; i++){
        c[i][0]=0;
    }
    for(int i=1; i<=n; i++)c[0][i]=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 <iostream>
#include <string>
#include <algorithm>
    using namespace std;
int lcs(string x,string y){
    int c[1010][1010];
    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(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

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

#define MAX 1000

int lcs(string X, string Y) {
    int c[MAX+1][MAX+1];
    int m = X.size();
    int n = Y.size();
    int i, j;
    int maxlen = 0;
    X = " " + X;
    Y = " " + Y;

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

    for(i = 1 ; i <= m ; i++ ) {
        for(j = 1 ; j <= n ; j++ ) {
            if (X[i] == Y[j]) {
                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];
            }
            maxlen = max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}

int main (void) {
    int N, i;
    string x, y;
    

    cin >> N;

    for(i = 0 ; i < N ; i++) {
        cin >> x;
        cin >> y;
        cout << lcs(x, y) << endl;
    }

    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; //X[0]???????????????????????\
    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;
}

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

int lcs(string x, string y) {
    int _lcs = 0;
    int x_size = x.size();
    int y_size = y.size();
    int dp[x_size + 1][y_size + 1];
    for (int i=0; i <= x_size; i++) {
        dp[i][0] = 0;
    }

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

    for (int i=1; i <= x_size; i++) {
        for (int j=1; j <= y_size; j++) {
            if (x[i-1] == y[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max({dp[i][j-1], dp[i-1][j]});
            }
        }
    }

    return dp[x_size][y_size];
}
int main() {
    int q;
    cin >> q;
    for (int i=0; i < q; i++) {
        string x, y;
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }

    return 0;
}