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>
#include<string>
int main()
{
  int n;
  int an[1000];
  int l=0;
  std::cin>>n;
  std::string x;
  std::string y;
  int ans[1001][1001];
  int j,k;
  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<=1000;j++){
      for(int k=0;k<=1000;k++){
	ans[j][k]=0;
      }
    }
    for(int j=1;j<=x.size();j++){
      for(int k=1;k<=y.size();k++){
	if(x[j]==y[k]){
	  ans[j][k]=ans[j-1][k-1]+1;
	}else{
	  if(ans[j][k-1]>ans[j-1][k]){
	    ans[j][k]=ans[j][k-1];
	  }else{
	    ans[j][k]=ans[j-1][k];
	  }
	}
      }
    }
    std::cout<<ans[x.size()-1][y.size()-1]<<'\n';  
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  string x, y;
  REP(i, n) {
    cin >> x >> y;
    auto xs = x.size();
    auto ys = y.size();
    x = ' ' + x;
    y = ' ' + y;
    vector<vi> dp(xs + 1, vi(ys + 1, 0));
    FOR(xi, 1, xs + 1) {
      FOR(yi, 1, ys + 1) {
        if (x[xi] == y[yi])
          dp[xi][yi] = dp[xi - 1][yi - 1] + 1;
        else
          dp[xi][yi] = max(dp[xi - 1][yi], dp[xi][yi - 1]);
      }
    }
    cout << dp[xs][ys] << endl;
  }
}

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

string S,T;
int x[10000],y[10000];
int dp[10000][10000];
char U[53]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int MAXN;

int main(){
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		MAXN=0;
		cin>>S>>T;
		for(int i=0;i<S.size();i++){
			for(int j=0;j<52;j++){
				if(S[i]==U[j]){
					x[i+1]=j;
				}
			}
		}
		for(int i=0;i<T.size();i++){
			for(int j=0;j<52;j++){
				if(T[i]==U[j]){
					y[i+1]=j;
				}
			}
		}
		for(int i=0;i<=T.size();i++){
			for(int j=0;j<=S.size();j++){
				if(i==0 || j==0){
					dp[i][j]=0;
				}
				else if(x[j]==y[i]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				else{
					dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
				}
			}
		}
		for(int i=0;i<=T.size();i++){
			for(int j=0;j<=S.size();j++){
				MAXN=max(MAXN,dp[i][j]);
			}
		}
		cout<<MAXN<<endl;
	}
	return 0;
}

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

using namespace std;

string s, t;

int main() {
	int n;
	cin >> n;
	while (n--) {
		//dp[i][j] := s???i??????????????§???t???j??????????????§?????£?????¨??????LCS
		vector<vector<int>> dp(2000, vector<int>(2000));
		cin >> s >> t;
		dp[0][0] = (s[0] == t[0]);
		for (int i = 1; i < s.size(); i++)dp[i][0] = (bool)(dp[0][0] + (s[i] == t[0]));
		for (int j = 1; j < t.size(); j++)dp[0][j] = (bool)(dp[0][0] + (s[0] == t[j]));
		
		for (int i = 1; i < s.size(); i++) {
			for (int j = 1; j < t.size(); j++) {
				if (s[i] == t[j])dp[i][j] = dp[i-1][j-1]+1;
				else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
		cout << dp[s.size() - 1][t.size() - 1] << endl;
	}
}

C++: #include <stdio.h>

int score[1010][1010];

int max2 (int a, int b){
  if (a >= b) return a;
  else return b;
}

int len_of_str(const char s[]){
  int num = 0;

  while(s[num]) num++;

  return num;
}


int main() {
  char a[1100];
  char b[1100];
  int datanum;
  scanf("%d",&datanum);
  for(int c = 0; c < datanum; c++){

  scanf("%1100s",a);
  scanf("%1100s",b);
  int num1 = len_of_str(a);
  int num2 = len_of_str(b);


  for(int i = num1; i > 0; i--) a[i] = a[i - 1];
  a[0] = ' ';
  for(int j = num2; j > 0; j--) b[j] = b[j - 1];
  b[0] = ' ';

  for(int i = 0; i <= num1; i++) score[i][0] = 0;
  for(int j = 0; j <= num2; j++) score[0][j] = 0;

  int maximum = 0;

  for(int i = 1; i<= num1; i++){
    for (int j = 1; j <= num2; j++){
      if (a[i] == b[j])score[i][j] = score[i-1][j-1] + 1;
      else if (a[i] != b[j]) score[i][j] = max2(score[i][j-1],score[i-1][j]);
      maximum = max2(maximum,score[i][j]);
    }
  }



  printf("%d\n",maximum);
}
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 10**9

int main() {
    int n,sx,sy;
    string x,y;
    cin >> n;
    rep(i,n){
        cin >> x >> y;
        sx = x.size();
        sy = y.size();
        vector<vector<int>> c(sy+1,vector<int>(sx+1));
        rep(j,sy+1)rep(k,sx+1) c.at(j).at(k) = -1;
        rep(j,sy+1)rep(k,sx+1){
            if (j==0 or k==0){
                c.at(j).at(k) = 0;
            }
            else if (x.at(k-1) == y.at(j-1)){
                c.at(j).at(k) = c.at(j-1).at(k-1) + 1;
            }
            else {
                c.at(j).at(k) = max(c.at(j).at(k-1),c.at(j-1).at(k));
            }
        }
        cout << c.at(sy).at(sx) << endl;
    }
}

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

using namespace std;


int main(){

  string str;
  string str2;
  int n,s,s2;
  int cou[1024][1024] = {{}};
  int max = 0;

  cin >> n;

  for(int i = 0;i < n;i++){

    cin >> str >> str2;

    str = ' ' + str;
    str2 = ' ' + str2;


    s = str.size();
    s2 = str2.size();

    for(int j = 1;j < s;j++){
      for(int k = 1;k < s2;k++){
	if(str[j] == str2[k]){
	  cou[j][k] = cou[j - 1][k - 1] + 1;
	  if(cou[j][k] > max) max = cou[j][k];
	  // cout << "a: str = " << str[j] << " str2 = " << str2[k] << " cou = " << cou[j][k] << endl;
	}
	else if(cou[j - 1][k] > cou[j][k - 1]){
	  cou[j][k] =  cou[j - 1][k];
	  // cout << "str = " << str[j] << " str2 = " << str2[k] << " cou = " << cou[j][k] << endl;
	}
	else {
	  cou[j][k] = cou[j][k - 1];
	  // cout << "str = " << str[j] << " str2 = " << str2[k] << " cou = " << cou[j][k] << endl;
	}
      }
    }


    cout << max << endl;
      
    max = 0;

    for(int j = 0;j <= s;j++){
      for(int k = 0;k <= s2;k++){
	cou[j][k] = 0;
      }
    }
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>

using namespace std;

int dp[1010][1010];



int solve() {

	string s,t;

	cin >> s >> t;


	int max_s = s.length();
	int max_t = t.length();

	memset(dp,0, sizeof(int) * 1010 * 1010);



	for (int i = 1; i <= max_s; i++) {
		for (int j = 1; j <= max_t; j++) {
			if (s.at(i - 1) == t.at(j -1)) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i][j - 1],dp[i -1][j]);			
			}
		}
	}
	return dp[max_s][max_t];
}

int main() {
	int q;

	cin >> q;

	for (int i = 0; i  < q; i++) {
		cout << solve() << endl;
	}

}