Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

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

int main(int argc, char const *argv[]) {
        int x; cin>>x;

        while (x--) {
                string s,t; cin>>s>>t;
                int n = s.length(); int m = t.length();
                vector<vector<int> > dp(n+1, vector<int>(m+1, 0));
                for (int i = 1; i <= n; ++i) {
                        for (int j = 1; j <= m; j++) {
                                if (s[i-1]==t[j-1]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
                                else {
                                        dp[i][j] = max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
                                }
                        }
                }
                cout << dp[n][m] << endl;
        }

        return 0;
}

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

int main() {
  int q; cin >> q;
  string A, B; cin >> A >> B;
  for (int i=0; i<q; i++) {
    vector<vector<int>> LCS(A.length()+1, vector<int>(B.length()+1,0));
    for (int j=1; j<=A.length(); j++) {
      for (int k=1; k<=B.length(); k++) {
        if(A[j]==B[k]) LCS[j][k]=LCS[j-1][k-1]+1;
        else LCS[j][k] = max(LCS[j-1][k],LCS[j][k-1]);
      }
    }
    cout << LCS[A.length()][B.length()]
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
long long dp[1002][1002];
int main() {
  int n;cin>>n;
  for(int i=0; i<n; i++){
  
  string a,b; cin>>a>>b;
  int al=a.size(); int bl=b.size();
  for (int i=0;i<1002;i++){for(int j=0;j<1002;j++){dp[i][j]=0;}}
  for (int j=0;j<al;j++){
  for (int k=0;k<bl;k++){
  if(a[j]==b[k]){dp[j+1][k+1]=dp[j][k]+1;}
  else{dp[j+1][k+1]=max(dp[j+1][k],dp[j][k+1]);}
  }
  }
  cout << dp[al][bl] << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
string s1,s2;
int memo[100][100];

int solve(int l1,int l2){
  if(memo[l1][l2] < 0)return memo[l1][l2];
  if(l1 < 0 or l2 < 0)return 0;
  //cout << s1[l1] << s2[l2] << endl;
  if(s1[l1] == s2[l2]){
    return memo[l1][l2] = solve(l1 - 1,l2 - 1) + 1;
  }
  return memo[l1][l2] = max(solve(l1,l2-1), solve(l1-1,l2));
}
int main(){
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){
    fill(*memo,*(memo+100),-1);
    cin >> s1 ;
    cin >> s2;
    cout << solve(s1.length(),s2.length()) - 1 << endl;
  }
}

C++: #include <iostream>
#include <cmath>
#define MAX_NUMBER 1001

using namespace std;

int main () {
  // 最长公共子序列
  int n;
  string x, y;
  int lcs, c[MAX_NUMBER][MAX_NUMBER];

  cin >> n;

  for (int k = 0; k < n; k++) {
    cin >> x;
    cin >> y;

    x = " " + x;
    y = " " + y;
    lcs = 0;
    for (int i = 0; i < MAX_NUMBER; i++)
      for (int j = 0; j < MAX_NUMBER; j++)
        c[i][j] = 0;
    
    for (int i = 1; i < x.length(); i++) {
      for (int j = 1; j < y.length(); 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]);
      }
    }

    cout << c[x.length() - 1][y.length() - 1] << endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s1[1005];
char s2[1005];
int chang[1005][1005];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s%s",s1,s2);
        int sl1=strlen(s1);
        int sl2=strlen(s2);
        for(int i=0;i<=sl1;i++){
                chang[i][0]=0;
        }
        for(int i=0;i<=sl2;i++){
                chang[0][i]=0;
        }
        for(int i=1;i<=sl1;i++){
            for(int j=1;j<=sl2;j++){
                if(s1[i]==s2[j]){
                    chang[i][j]=chang[i-1][j-1]+1;
                }
                else {
                    chang[i][j]=max(chang[i-1][j],chang[i][j-1]);
                }
            }
        }
        printf("%d\n",chang[sl1][sl2]);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define For(I,A,B) for(int I=(A); I < (B); ++I)
int c[1005][1005];
int main()
{
int t;
string p;
cin>>t;
getline(cin,p);
while(t--){

int x,y,z,k=0,l,i,j;
string a,b;

 For(i,0,1005)
 For(j,0,1005)
 c[i][j]=0;

 getline(cin,a);
 getline(cin,b);
 x=a.length();
 y=b.length();

 For(i,1,x+1)
 For(j,1,y+1)
 {
     if(a[i-1]==b[j-1]) c[i][j]=c[i-1][j-1]+1;
     else  c[i][j]=max(c[i-1][j],c[i][j-1]);
 }
    cout<<c[x][y]<<endl;

}

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include<string.h>
using namespace std;
int LCS(char *x,char *y);
char x[1001], y[1001];
int lcs[1001][1001];
int main()
{
	int q,i,j;

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

int LCS(char *x, char *y)
{
	int i, j;
	int len_x, len_y;
	len_x = strlen(x);
	len_y = strlen(y);
	for (i = 0; i < len_x; i++) {
		for (j = 0; j < len_y; j++) {
			lcs[i][j] = '\0';
		}
		//cout << endl;
	}
	for (i = 0; i < len_x; i++) {
		if (x[i] == y[0]) {
			lcs[i][0] = 1;
		}
		else {
			lcs[i][0] = 0;
		}
	}
	for (i = 0; i < len_y; i++) {
		if (x[0] == y[i]) {
			lcs[0][i] = 1;
		}
		else {
			lcs[0][i] = 0;
		}
	}

	for (i = 0; i < len_x; i++) {
		for (j = 0; j < len_y; j++) {
			if (x[i] == y[j]) {
				lcs[i][j] = lcs[i - 1][j - 1] + 1;
				//printf("lcs[%d][%d]=%d\n", i, j, lcs[i - 1][j - 1] + 1);
			}
			if (x[i] != y[j]) {
				lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
				//printf("lcs[%d][%d]=%d\n", i, j, max(lcs[i - 1][j], lcs[i][j - 1]));
			}
		}
	//cout << endl;

	}
	for (i = 0; i < len_x; i++) {
		for (j = 0; j < len_y; j++) {
			//printf("%d ", lcs[i][j]);
		}
		//cout << endl;
	}
	//cout << "len_x=" << len_x << endl << "len_y=" << len_y << endl;
			
	return lcs[i-1][j-1];
}