Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
#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++: //#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int Q, DP[1005][1005];
string X, Y;

int Solve(){
  int N = X.length(), M = Y.length();
  fill((int*)DP, (int*)(DP + N + 1), 0);

  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= M; j++){
      if (X[i - 1] == Y[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[N][M] << endl;
  return 0;
}

int main(){
  cin >> Q;
  for (int i = 0; i < Q; i++){
    cin >> X >> Y;
    Solve();
  }

  return 0;
}

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

using namespace std;

int q;
char X[1000], Y[1000];
int dp[1001][1001];

int main(void) {

    scanf("%d", &q);

    for (int i = 0; i < q; ++i) {
        scanf("%s %s", X, Y);
        int xlen = strlen(X), ylen = strlen(Y);
        for (int x = 0; x < xlen; ++x) {
            for (int y = 0; y < ylen; ++y) {
                if (X[x] == Y[y]) {
                    dp[x + 1][y + 1] = dp[x][y] + 1;
                }
                else {
                    if (dp[x + 1][y] > dp[x][y + 1]) {
                        dp[x + 1][y + 1] = dp[x + 1][y];
                    }
                    else {
                        dp[x + 1][y + 1] = dp[x][y + 1];
                    }
                }
            }
        }
        printf("%d\n", dp[xlen][ylen]);
        memset(dp, 0, sizeof(int)*1001*1001);
    }
    printf("\n");
    return 0;
}

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

using ll = long long;
using Field = vector<vector<ll>>;
using Graph = vector<vector<ll>>;
using VI = vector<int>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

int q;


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    cin >> q;

    REP(_, q) {

        string A, B;
        vector<vector<int>> dp(1010, vector<int>(1010));

        cin >> A >> B;

        for (int i = 0; i < A.size(); i++) {
            if (A[i] == B[0]) dp[i][0] = 1;
            chmax(dp[i+1][0], dp[i][0]);
        }
        for (int i = 0; i < B.size(); i++) {
            if (A[0] == B[i]) dp[0][i] = 1;
            chmax(dp[0][i + 1], dp[0][i]);
        }
        
        for (int i = 1; i < A.size(); i++) {
            for (int j = 1; j < B.size(); j++) {
                if (A[i] == B[j]) {
                    chmax(dp[i][j], dp[i - 1][j - 1] + 1);
                } else {
                    chmax(dp[i][j], dp[i][j-1]);
                    chmax(dp[i][j], dp[i-1][j]);
                }
            }
        }



        cout << dp[A.size() - 1][B.size() - 1] << 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 <cmath>
using namespace std;

int LCS(string str1, string str2)
{
  int n1, n2;
  n1 = (int)(str1.length());
  n2 = (int)(str2.length());
  int dp[n1+1][n2+1];

  for(int i = 0; i < n1 + 1; i++) {
    for(int j = 0; j < n2 + 1; j++) {
      dp[i][j] = 0;
    }
  }


  int maxi, s, t;
  for(int i = 1; i < n1 + 1; i++) {
    for(int j = 1; j < n2 + 1; j++) {
      if(str1[i-1] != str2[j-1]) {
	dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }
      else {
	dp[i][j] = dp[i-1][j-1] + 1; //(i-1,j)と(i,j-1)の場合はstr1[i]とstr2[j]が考慮されているので斜め移動のみ
      }
    }
  }
  /*
  for(int i = 0; i < n1 + 1; i++) {
    for(int j = 0; j < n2 + 1; j++) {
      cout << dp[i][j] << " ";
    }
    cout << "\n";
  }
  */
  maxi = 0;
  for(int i = 0; i < n1 + 1; i++) {
    for(int j = 0; j < n2 + 1; j++) {
      if(maxi < dp[i][j]) {
	maxi = dp[i][j];
      }
    }
  }
  

  return maxi;
}

int main()
{
  int q;
  cin >> q;
  string str1[q], str2[q];
  for(int i = 0; i < q; i++) {
    cin >> str1[i];
    cin >> str2[i];
  }

  for(int i = 0; i < q; i++) {
    cout << LCS(str1[i], str2[i]) << "\n";
  }

  return 0;
}