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 <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1010;
char x[N],y[N];
int c[N][N];
int lcs(char x[],char y[]){

    int lenx = strlen(x+1);
    int leny = strlen(y+1);

    for (int i=0; i<=lenx; i++) {
        c[i][0] = 0;
    }
    for(int j=1;j<=leny;j++){
        c[0][j] = 0;
        
    }

    for(int i=1;i<lenx;i++){
        for(int j=1;j<leny;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]);
        }
    }
    return c[lenx][leny];
}
int main(){
    int q;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        gets(x+1);
        gets(y+1);
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

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

int main(){
  int dp[1000][1000]={0};
  int n,m=0;
  int ans[150];
  std::string str1,str2;
  std::cin>>n;
  for(int k=0;k<n;k++){
    std::cin>>str1>>str2;
    for(int i=1;i<=str1.size();i++){
      for(int j=1;j<=str2.size();j++){
	if(str1[i-1]==str2[j-1]){
	  dp[i][j]=dp[i-1][j-1]+1;
	}else{
	  dp[i][j]=std::max(dp[i-1][j],dp[i][j-1]);
	}
      }
    }
    ans[m]=dp[str1.size()][str2.size()];
    m++;
  }
  for(int i=0;i<m;i++){
    std::cout<<ans[i]<<"\n";
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>

class TLcsSolver
{
    int FTable[1001][1001];
    const char* FArray1;
    const char* FArray2;
    const int Fn1;
    const int Fn2;

    int Count(int i, int j)
    {
        if(i == 0 || j == 0) return 0;
        if(FArray1[i-1] == FArray2[j-1]){
            return FTable[i-1][j-1] + 1;
        }
        return std::max(FTable[i-1][j], FTable[i][j-1]);
    }
    void Solve()
    {
        for(std::size_t i = 1; i < Fn1; ++i){
            for(std::size_t j = 1; j < Fn2; ++j){
                FTable[i][j] = Count(i, j);
            }
        }
    }
    void Print()const
    {
        for(std::size_t i = 0; i < Fn1; ++i){
            for(std::size_t j = 0; j < Fn2; ++j){
                printf("%d\t", FTable[i][j]);
            }
            printf("\n");
        }
    } 
public:
    TLcsSolver(const char* a, const char* b)
     : FArray1(a), FArray2(b)
     , Fn1(std::strlen(a)), Fn2(std::strlen(b))
    {
        Solve();
        // Print();
    }
    int Answer()const
    {
        return FTable[Fn1-1][Fn2-1];
    }
};

int main()
{
    int n;
    std::scanf("%d\n", &n);
    char a[1001];
    char b[1001];
    for(int i = 0; i < n; ++i){
        std::fgets(a, 1000, stdin);
        std::fgets(b, 1000, stdin);
        std::printf("%d\n", TLcsSolver(a, b).Answer());
    }
    return 0;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
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;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;

int dp[1010][1010];

int main(int argc, char const* argv[])
{
  int q; cin >> q;
  rep(i_, q){
    string s, t; cin >> s >> t;
    rep(i, sz(s) + 1)rep(j, sz(t) + 1)dp[i][j] = 0;
    rep(i, sz(s)){
      rep(j, sz(t)){
        chmax(dp[i+1][j+1], dp[i][j+1]);
        chmax(dp[i+1][j+1], dp[i+1][j]);
        if(s[i] == t[j])chmax(dp[i+1][j+1], dp[i][j] + 1);
      }
    }
    cout << dp[sz(s)][sz(t)] << endl;
  }
  return 0;
}