Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	results := []int{}
	for i := 0; i < n; i++ {
		results = append(results, resolveInstance())
	}
	for _, v := range results {
		fmt.Println(v)
	}
	return
}

func resolveInstance() int {
	x, y := scanString(sc), scanString(sc)
	lx, ly := len(x), len(y)
	dp := make([][]int, lx+1)
	dp[0] = make([]int, ly+1)
	for i := 1; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
		dp[i][0] = dp[i-1][0]
		for j := 1; j <= ly; j++ {
			dp[i][j] = dp[i-1][j]
			if dp[i][j] < dp[i][j-1] {
				dp[i][j] = dp[i][j-1]
			}
			if x[i-1] == y[j-1] {
				cL := dp[i-1][j-1] + 1
				if dp[i][j] < cL {
					dp[i][j] = cL
				}
			}
		}
	}
	return dp[lx][ly]
}

const (
	remove = 0 + iota
	match
)

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

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

int lcs(string s,string t)
{
  int c[1005][1005];
  int m=s.size(),n=t.size(),len=0;

  for(int i=0;i<=m;i++) c[i][0]=0;
  for(int i=0;i<=n;i++) c[0][i]=0;


  for(int i=1;i<=m;i++)
  {
    for(int j=1;j<=n;j++)
    {
      if(s.at(i-1)==t.at(j-1)) c[i][j]=c[i-1][j-1]+1;
      else c[i][j]=max(c[i-1][j],c[i][j-1]);

      len=max(len,c[i][j]);
    }
  }

  return len;
}

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

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 LMAX=0;
  int m=X.size(), n=Y.size();

  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]);
      }
      LMAX=max(LMAX, c[i][j]);
    }
  }

  return LMAX;
}

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