Go: package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	for q := 0; q < n; q++ {
		var s1, s2 string
		fmt.Scan(&s1, &s2)
		s1, s2 = " " + s1, " " + s2

		dp := make([][]int, len(s1))
		for i := range dp {
			dp[i] = make([]int, len(s2))
		}

		max := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					dp[i][j] = dp[i-1][j-1] + 1
				} else {
					dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
				}
				max = Max(max, dp[i][j])
			}
		}

		fmt.Println(max)
	}
}

func Max(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <utility>
#define rep(i, n) for(int i = 0; i < n; i++);

using namespace std;

const int INF = 1000000007;
const double PI = acos(-1.0);
typedef long long llong;

const int N = 10000;

int search(string X, string Y)
{
	int c[1000 + 1][1000 + 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 input1, input2;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> input1 >> input2;
		cout << search(input1, input2) << endl;
	}

	return 0;
	

}

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

string X;
string Y;

int calc(int x_s, int x, int y, int length){
    if (X[x] == '\0') return length;
    int y_ = Y.find(X[x], y);
    if (y_ == string::npos) {
        return max(length, calc(x_s + 1, x_s + 1, 0, 0));
    }
    return calc(x_s, x + 1, y_ + 1, length + 1);
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> X;
        cin >> Y;
        cout << calc(0, 0, 0, 0) << endl;
    }

    return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(){
   char str_s[128], str_p[128];
   int a[100]=0;
   int i, j, c, h, n, m;
   scanf("%d",n);
   for(i=0;i < n;i++){
      scanf("%s",str_s);
      scanf("%s",str_p);
      n=strlen(str_s);
      m=strlen(str_p);
      c=0;
      h=0;
      for(i=0;i < n;i++){
         for(j=h;j < m;j++){
            if(str_s[i] ==str_p[j]){
               h=j+1;
               c++;
               break;
            }
         }
      }
      printf("%d\n, c");
   }

   return 0;
}

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

int main(){
  int i,j,n,c[1001][1001];
  string x,y;
  cin >> n;
  while(n>0){
    n--;
    cin >> x;
    cin >> y;

    int lenx = x.size();
    int leny = y.size();

    for(i = 1; i < lenx; i++){
      c[i][0] = 0;
    }
    for(j = 1; j < leny; j++){
      c[0][j] = 0;
    }
  
    for(i = 0; i < lenx; i++){
      for(j = 0; j < leny; 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];
	}
      }
    }
    cout << c[lenx-1][leny-1] << endl;
  }
  return 0;
}

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

int S[1001][1001];

void prep(string str1, string str2, int len1, int len2)
{
    int a, b, i;
    S[0][0] = 0;
    for(i = 1; i <= len1; i++){ S[i][0] = 0; }
    for(i = 1; i <= len2; i++){ S[0][i] = 0; }
    for(a = 1; a <= len1; a++){
        for(b = 1; b <= len2; b++){
            if(str1[a - 1] == str2[b - 1]){ S[a][b] = 1; }else{ S[a][b] = 0; }
        }
    }
    return;
}

int main()
{
    int i, a, b, q, len1, len2;
    cin >> q;
    string str1, str2;

    for(i = 0; i < q; i++){
        cin >> str1 >> str2;
        len1 = str1.size();
        len2 = str2.size();
        prep(str1, str2, len1, len2);
        for(a = 1; a <= len1; a++){
            for(b = 1; b <= len2; b++){
                if(S[a][b]){ S[a][b] = S[a - 1][b - 1] + 1; }
                else{ S[a][b] = max(S[a - 1][b], S[a][b - 1]); }
            }
        }
		cout << S[len1][len2] << 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;
    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 <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int lcs(string X, string Y) {
    int m = X.size();
    int n = Y.size();
    int c[m+1][n+1];
    int maxl = 0;
    X = ' ' + X;    // insert empty to X[0]
    Y = ' ' + Y;    // insert empty to Y[0]
    for (int i = 0; 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]);
            }
        }
    }

    return c[m][n];
}

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

    for (int i = 0; i < n; i++) {
        string s1, s2;
        cin >> s1 >> s2;
        printf("%d\n", lcs(s1, s2));
    }
    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++) {
		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];
}

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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int main() {
	int n; cin >> n;

	int maxl;
	int	dp[1001][1001] = {};
	string s1, s2;
	REP( i, n ) {
		cin >> s1 >> s2;
		maxl = 0;
		FOR( j, 1, s1.size() + 1 ) {
			FOR( k, 1, s2.size() + 1 ) {
				if( s1[j] == s2[k] ) {
					dp[j][k] = dp[j - 1][k - 1] + 1;
				} else {
					dp[j][k] = max( dp[j - 1][k], dp[j][k - 1] );
				}
				maxl = max( dp[j][k], maxl );
			}
		}

		cout << maxl << endl;
	}
}