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 <string>
#include <algorithm>

#define N 1000

int lsc(string x,string y){
    int c[N+1][N+1];
    int m=x.size();
    int n=y.size();
    int maxl=0;

    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;
}

using namespace std;

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

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>

using namespace std;

static const int N = 1000;

int c[N + 1][N + 1];
int lcs(string s1, string s2){
	int m = s1.size();
	int n = s2.size();
	int maxL = 0;

	s1 = ' ' + s1;
	s2 = ' ' + s2;
	for (int i = 1; i <= m; ++i) c[i][0] = 0;
	for (int i = 1; i <= n; ++i) c[0][i] = 0;

	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++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]);
			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 <cstring> 
using namespace std;
int c[1001][1001];

int lcs(string x, string y)
{
    int maxl = 0;
    int m = x.length(), n = y.length();
 
    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-1] == y[j-1])
            { 
                // if(i==0 || j==0) c[i][j] = 1;
                c[i][j] = c[i-1][j-1] + 1; 
            }else
            {
                // if(i==0 || j==0) c[i][j] = 0;
                c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
            maxl = max(maxl, c[i][j]);
        } 
    } 
    // printf("%d\n", c[m][n]);
    return c[m][n];
}

int main()
{
    string x,y;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        int ans = lcs(x, y);
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long llong;

static const int MAX = 1000;
int dp[MAX + 1][MAX + 1];

void lcs(string s1, string s2){
    for (int i = 0; i < MAX + 1; i++){
        for (int j = 0; j < MAX + 1; j++) dp[i][j] = 0;
    }
    
    for (int i = 0; i < s1.size(); i++){
        for (int j = 0; j < s2.size(); j++){
            if (s1[i] == s2[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
            else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        }
    }
    cout << dp[s1.size()][s2.size()] << endl;
}

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

    string s1, s2;
    for (int i = 0; i < n; i++){
        cin >> s1 >> s2;
        lcs(s1, s2);
    }

    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;
  
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (X[i] == Y[j]) 
        if (i == 0 || j == 0) 
          c[i][j] = 1;
        else 
          c[i][j] = c[i - 1][j - 1] + 1;
      else
        if (i != 0 && j != 0) 
          c[i][j] = max(c[i][j - 1], c[i - 1][j]);
        else
          c[i][j] = 0;
      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;
}