Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		strX := nextText(sc)
		strY := nextText(sc)
		fmt.Println(calcLcs(strX, strY))
	}
}

func calcLcs(strX, strY string) int {
	lenX, lenY := len(strX), len(strY)
	memo := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		memo[i] = make([]int, lenY+1)
	}

	lcs := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if strX[i-1] == strY[j-1] {
				memo[i][j] = memo[i-1][j-1] + 1
			} else {
				if memo[i-1][j] > memo[i][j-1] {
					memo[i][j] = memo[i-1][j]
				} else {
					memo[i][j] = memo[i][j-1]
				}
			}
			if memo[i][j] > lcs {
				lcs = memo[i][j]
			}
		}
	}
	return lcs
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int solve(std::string x, std::string y) {
  int m = x.length();
  int n = y.length();
  int lcs[m + 1][n + 1];
  rep(i, m + 1) lcs[i][0] = 0;
  rep(j, n + 1) lcs[0][j] = 0;

  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (x[i - 1] == y[j - 1])
        lcs[i][j] = lcs[i - 1][j - 1] + 1;
      else
        lcs[i][j] = std::max(lcs[i - 1][j], lcs[i][j - 1]);
    }
  }

  return lcs[m][n];
}

int main() {
  int n;
  std::cin >> n;
  std::string x, y;

  rep(i, n) {
    std::cin >> x >> y;
    std::cout << solve(x, y) << '\n';
  }
  return 0;
}

C++: q = int(input())
ans = []
for i in range(q):
    x = input()
    y = input()
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        s = x[i]
        dp2 = dp1[:]
        for j in range(m):
            if s == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    ans.append(dp1[-1])
print(*ans, sep="\n")

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

using namespace std;

//L[i][j] X[0]..X[i]??¨X[0]..Y[j]???LCS
int L[1001][1001]={};
int main(){
  int testnum;
  cin>>testnum;
  for(int t=0;t<testnum;++t){
    string X,Y;
    cin>>X>>Y;

    for(int i=1;i<=X.length();++i){
      for(int j=1;j<=Y.length();++j){
        if(X[i]==Y[j])
          L[i][j] = 1 + L[i-1][j-1];
        else
          L[i][j] = max(L[i][j-1],L[i-1][j]);
      }
    }

    cout << L[X.length()][Y.length()] << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll q;
  cin >> q;
  string str1,str2;
  rep(_,q){
    cin >> str1;
    cin >> str2;
    ull len1 = str1.size();
    ull len2 = str2.size();
    vector<vector<ll>> dp(len1+1,vector<ll> (len2+1,0));
    rep(i,len1){
      rep(j,len2){
        dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
        if(str1[i] == str2[j]){
          chmax(dp[i+1][j+1],dp[i][j] + 1);
        }
      }
    }
    cout << dp[len1][len2] << endl;
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(void){
   long L[1010][1010], Z; 
   string X, Y; 
   int q;  
    cin >> q; 
  for(int k=0; k<q; k++){ 
      cin >> X;  
      cin >> Y; 
      for(int i=0; i<X.size(); i++){   
            for(int j=0; j<Y.size(); j++){
           L[i][j] = 0;
            }
      }
      for(int i=0; i<X.size(); i++){
       for(int j=0; j<Y.size(); j++){
           if(i<=0 || j<=0){
               if(X[i]==Y[j])  L[i][j]=1;
               else            L[i][j]=0;
           }
           else if(X[i] == Y[j])
                L[i][j]=1+L[i-1][j-1];
           else L[i][j]=max(L[i][j-1], L[i-1][j]); 
          Z=L[i][j];
       } 
     } 
     cout << Z << 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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;

const int MAX = 1024;
const int INF = 1<<29;

ll dp[MAX][MAX];

ll LCS(string s, string t) {
    memset(dp, 0LL, sizeof(dp));
    int sl = (int)s.size(), tl = (int)t.size();
    rep(sl, i) rep(tl, 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]);
    }
    return dp[sl][tl];
}

void solve(void){
    int N;
    cin >> N;
    rep(N, i) {
        string s, t;
        cin >> s >> t;
        cout << LCS(s, t) << endl;
    }
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
int main(){
  int q;
  std::cin>>q;
  std::vector<std::string> str1,str2;
  std::string str;
  for(int i=0;i<q;i++){
    std::cin>>str;
    str1.push_back(str);
    std::cin>>str;
    str2.push_back(str);
    //std::cout<<str1[i][0]<<"\n";
    //std::cout<<str2[i][0]<<"\n";
  }
  
 
  for (int i = 0; i < q; i++) {
	  int ans[str1[i].length()+1][str2[i].length()+1];
	  for (int j = 0; j < str1[i].length() + 1; j++) {
		  for (int k = 0; k < str2[i].length() + 1; k++) {
			  
			  if (j == 0 || k == 0) {
				  ans[j][k] = 0;
			  }else {
				  //std::cout << " str1= " << str1[i][j-1] << " str2= " << str2[i][k-1] << " \n ";
				  if (str1[i][j-1] == str2[i][k-1]){
					  //std::cout << "ppp";
					  ans[j][k] = std::max({ ans[j - 1][k - 1] + 1,ans[j - 1][k],ans[j][k - 1] });
					  //ans[j][k] = std::max({ 1,2,3 });
				  }else {
					  ans[j][k] = std::max(ans[j - 1][k], ans[j][k - 1]);
				  }
			  }
			  //std::cout << ans[j][k] << " ";
			  
		  }
		  //std::cout << "\n";
	  }
	  std::cout << ans[str1[i].length()][str2[i].length()] << "\n";
  }
  

  return 0;
}