Go: package main

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

func max(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = " " + s1 , " " + s2
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					c[i][j] = c[i-1][j-1] + 1
				} else {
					c[i][j] = max(c[i-1][j], c[i][j-1])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

C++: #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

const int N = 1001;

int lcs(string x, string y)
{
	vector<vector<int>> c(N, vector<int>(N));

	int m = x.size();
	int n = y.size();

	int maxl = 0;

	x = " " + x;
	y = " " + y;

	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (x.at(i) == y.at(j))
			{
				c.at(i).at(j) = c.at(i - 1).at(j - 1) + 1;
			}
			else
			{
				c.at(i).at(j) = max(c.at(i).at(j - 1), c.at(i - 1).at(j));
			}

			maxl = max(maxl, c.at(i).at(j));
		}
	}

	return maxl;
}

int main()
{
	int n;
	for (cin >> n; n--;)
	{
		string s0, s1;
		cin >> s0 >> s1;

		cout << lcs(s0, s1) << endl;
	}
}

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

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

    for (int i = 0; i < n; i++)
    {
        string X, Y;
        cin >> X >> Y;
        vector<vector<int>> dp(X.size() + 1);
        for (int j = 0; j < dp.size(); j++)
        {
            dp[j].resize(Y.size() + 1, 0);
        }

        int res = 0;
        for (int j = 0; j < X.size(); j++)
        {
            for (int k = 0; k < Y.size(); k++)
            {
                if (X[j] == Y[k])
                {
                    dp[j + 1][k + 1] = dp[j][k] + 1;
                    res = max(res, dp[j + 1][k + 1]);
                }
                else
                {
                    dp[j + 1][k + 1] = max(dp[j][k + 1], dp[j + 1][k]);
                }

                // cout << "########## (" << j << ", " << k << ") ##########" << endl;
                // cout << dp[j + 1][k + 1] << endl;
            }
        }

        cout << res << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int main(){
  int q;
  cin>>q;
  for(int cn=0;cn<q;cn++){
    string x,y;
    cin>>x>>y;
    memset(dp,0,sizeof(dp));
    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;
	dp[i][j]=max(dp[i-1][j],dp[i][j]);
	dp[i][j]=max(dp[i][j-1],dp[i][j]);
      }
    }
    cout<<dp[x.size()][y.size()]<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAX 1000

int main(){
  int n;
  cin>>n;
  string a,b;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    int C[MAX+1][MAX+1]={0};
    for(int i=1;i<=a.size();i++){
      for(int j=1;j<=b.size();j++){
        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[a.size()][b.size()]<<endl;
  }

}

C++: #include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

int dp[1001][1001];
int main(){
	int n = 0;
	cin >> n;
	int x, y;
	string X, Y;
	r(k, n){
		cin >> X >> Y;
		x = X.length();
		y = Y.length();
		r(i, x+1)
			r(j, y+1)
				dp[i][j] = 0;

		r(i, x){
			r(j, y){
				if(X[i] == Y[j]){
					if(i == 0 || j == 0){
						dp[i][j] = 1;
					}else{
						dp[i][j] = dp[i-1][j-1] + 1;
					}
				}else{
					if(i == 0 || j == 0){
						dp[i][j] = 0;
					}else{
						dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
					}
				}

			}
		}
		cout << dp[x-1][y-1] << endl;
	}
	return 0;
}

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

using namespace std;

int maxa[1000];
int main(){
  int n;
  int k;
  int count;
  cin>>n;
  char X[1001];
  char Y[1001];
  for(int i=0;i<n;i++){
    cin>>X;
    cin>>Y;

    for(int a=0;X[a]!='\0';a++){
    count=0;
    k=0;
      for(int s=a;X[s]!='\0';s++){
	for(int j=k;Y[j]!='\0';j++){
	  if(X[s]==Y[j]){
	    //	    cout<<X[s];
	    count++;
	    k=j;
	    break;
	  }
	}
      }
      if(maxa[i]<count)maxa[i]=count;
    }
  }
  for(int i=0;i<n;i++){
    cout<<maxa[i]<<endl;
  }
  
  return 0;
}

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

int n;
string x, y;
bool mat[1000][1000];
int a[1000][1000];

int max(int i, int j) {
	int r = (!mat[i - 1][j] ? a[i - 1][j] : 0);
	r = ((!mat[i][j - 1] && a[i][j - 1] > r) ? a[i][j - 1] : r);
	return r > a[i - 1][j - 1] ? r : a[i - 1][j - 1];
}

int main(){
	cin >> n;
	for (int ia = 0; ia < n; ia++) {
		int ans = 0, p = 0;
		cin >> x >> y;
		for (int i = 0; i < x.length(); i++) {
			mat[i][0] = x[i] == y[0] ? true : false;
			a[i][0] = mat[i][0] ? 1 : 0;
		}
		for (int i = 1; i < y.length(); i++) {
			mat[0][i] = x[0] == y[i] ? true : false;
			a[0][i] = mat[0][i] ? 1 : 0;
		}
		for (int i = 1; i < x.length(); i++) {
			for (int j = 1; j < y.length(); j++) {
				mat[i][j] = x[i] == y[j] ? true : false;
				a[i][j] = max(i, j) + (mat[i][j] ? 1 : 0);
				if (a[i][j] > p) p = a[i][j];
			}
		}
		if (a[x.length() - 1][0] > p) p = a[x.length() - 1][0];
		if (a[0][y.length() - 1] > p) p = a[0][y.length() - 1];
		cout << p << endl;
	}


	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <tuple>
using namespace std;

int solve(string& X, string& Y){
  int x_size = X.size();
  int y_size = Y.size();
  
  vector<vector<int>> dp(y_size+1);
  for(int i=0;i<=y_size;i++){
    for(int j=0;j<=x_size;j++){
      dp[i].push_back(0);
    }
  }
  
  for(int i=1;i<=y_size;i++){
    for(int j=1;j<=x_size;j++){
      if(Y[i-1]==X[j-1]){
        dp[i][j] = dp[i-1][j-1]+1;
      } else {
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  
  /*
  for(int i=0;i<=y_size;i++){
    for(int j=0;j<=x_size;j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  
  return dp[y_size][x_size];
}

int main(void){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    string X,Y;
    cin >> X >> Y;
    
    int lcs = solve(X,Y);
  
    cout << lcs << endl;
  }
}

C++: #include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int solve(string x, string y){
    //dp[i][j] xの i文字目、yのj文字目までの最長共通部分列の長さ
    int dp[1010][1010] = {};

    rep(i, x.size())rep(j, y.size()){
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        if(x[i] == y[j])dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
    }

    return dp[x.size()][y.size()];
}
int main(){
    int q;
    cin >> q;

    int ans[q];

    rep(i, q){
        string x, y;
        cin >> x >> y;
        
        ans[i] = solve(x, y);
    }

    rep(i, q)cout << ans[i] << endl;
}