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 <stdio.h>
#include <string.h>
#define N 1000

void Ics(char *X, char *Y)
{
   int c[N][N];
   int m, n, i, j;

   m = strlen(X);
   n = strlen(Y);

   for ( i = 0; 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 - 1 ] == Y[ j - 1] ) {
            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 ];
         }
      }
   }
   printf("%d\n", c[ m ][ n ]);
}
     
int main()
{
   int n, i;
   char X[N], Y[N];

   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) {
      scanf("%s%s", X, Y);
      Ics(X, Y);
   }
   return 0;
}

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

using namespace std;

const int MAXN = 1010;

int main(int argc, char const *argv[]) {
  int q;
  cin >> q;
  for (auto k = 0; k < q; k++) {
    vector<vector<int>> dp(MAXN, vector<int>(MAXN, 0));
    string s1, s2;
    cin >> s1 >> s2;
    auto n = s1.size();
    auto m = s2.size();
    for (size_t i = 0; i < n; i++) {
      for (size_t j = 0; j < m; j++) {
        if (s1[i] == s2[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[n][m] << 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 = 0; i <= m; i++) c[i][0] = 0;
	for(int j = 0; 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++: #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
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 = 0; i < m; i++) c[i][0] = 0;
	for (int j = 0; 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]);
			}
		}
	}
	maxl = c[m][n];
	return maxl;
}

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


int main() {
    int q;
    cin>>q;
    
    while(1){
        //cout<<q<<endl;
        if(!q)break;
        string x,y;
        cin>>x>>y;
        int n=x.size();
        int m=y.size();
        int dp[1050][1050];
        for(int i=1;i<=m;i++){
            rep(j,n+1){
               dp[j][i]=0;
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(x[i]==y[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[n][m]<<endl;
        q--;
    }
    
    
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int dp[1001][1001];
string s,t;
int n,m,a,ans;
int main(){
  cin>>a;
  for(int k=0;k<a;k++){
    cin>>s>>t;
    for(int i=0;i<=1000;i++)
      for(int j=0;j<=1000;j++)
    dp[i][j]=0;
    m=s.size();
    n=t.size();
    ans=0;
    for(int i=1;i<=m;i++){
      for(int j=1;j<=n;j++){
    if(s[i-1]==t[j-1]){
      dp[i][j]=dp[i-1][j-1]+1;
    }else{
      dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
      }
    } 
    cout<<dp[m][n]<<endl;
  }
  return 0;
}

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

int lcs(string x, string y) {
	int m = x.size();
	int n = y.size();
	//cout<<m<<n<<endl;
	int maxl = 0;
	int A[1001][1001]={};
	x = ' ' + x;
	y = ' ' + y;
//	cout<<x<<y;
	for (int i = 0;i <= m;i++) {
		A[i][0] = 0;
	}
	for (int j = 0;j <= n;j++) {
		A[0][j] = 0;
	}

	for (int i = 1;i <= m;i++) {
		for (int j = 1;j <= n;j++) {
		//	cout<<x[i]<<y[j]<<endl;
			if (x[i] == y[j]) {
					A[i][j] = A[i-1][j-1] + 1;
			}
	     	else {
					A[i][j] = max(A[i - 1][j], A[i][j - 1]);
			}

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

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

	}
	return 0;
}

C++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

int solve(const string& str1, const string& str2) {
  int max_ = 0;
  vector<vector<int>> buf(str1.size(), vector<int>(str2.size(), 0));
  for (size_t j = 0; j < str2.size(); ++j) {
    for (size_t i = 0; i < str1.size(); ++i) {
      auto prev1 = j == 0 ? 0 : buf[i][j - 1];
      auto prev2 = i == 0 ? 0 : buf[i - 1][j];
      buf[i][j] = max(prev1, prev2);
      if (str1[i] == str2[j]) {
        auto p = i == 0 || j == 0 ? 0 : buf[i - 1][j - 1];
        buf[i][j] = max(buf[i][j], p + 1);
        max_ = max(max_, buf[i][j]);
      }
    }
  }
  return max_;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string str1;
    string str2;
    cin >> str1 >> str2;
    auto res = solve(str1, str2);
    cout << res << endl;
  }
}