Go: package main

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

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()

	n := nint()
	xList := make([]string, n)
	yList := make([]string, n)

	for i:=0;i<n ;i++  {
		xList[i] = nstr()
		yList[i] = nstr()
	}

	for i := 0; i<n	; i++  {
		fmt.Println(lcs(xList[i], yList[i]))
	}

}

func lcs(x string, y string) int{
	var m = len(x)
	var n = len(y)

	c := make([][]int, m+1)
	for i:= range c{
		c[i] = make([]int, n+1)
	}
	for i:=	1;i<=m ;i++  {
		for j:=1;j<=n ;j++  {
			if x[i-1] == y[j-1]{
				c[i][j] = c[i-1][j-1] + 1
			}else{
				c[i][j] = int(math.Max(float64(c[i-1][j]), float64(c[i][j-1])))
			}


		}
	}
	return c[m][n]

}


func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

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

int CS(string a, int lena, string b, int lenb)
{
    int ret;

    if ((lena > 0) && (lenb > 0)) {
        if (a[lena] == b[lenb]) {
            ret = CS(a, lena - 1, b, lenb - 1) + 1;
        }
        else {
            ret = max(CS(a, lena, b, lenb - 1), CS(a, lena - 1, b, lenb));
        }
    }
    else {
        ret = 0;
    }

    return ret;
}

int LCS(string a, string b)
{
    int ret;
    int len1, len2;

    len1 = a.length();
    len2 = b.length();
    ret  = CS(a, len1, b, len2);

    return ret;
}

int main(void)
{
    int i;
    int num;
    int ret;
    string a, b;

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        cin >> a;
        cin >> b;
        ret = LCS(a, b);
        printf("%d\n", ret);
    }

    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
  char str1[1000],str2[1000];
  int LCS[1000][1000]={0};
  int length1,length2;
  int n;
  ios::sync_with_stdio(false);
  scanf("%d",&n);
  for(int s=1;s<=n;s++){
   while(cin>>str1>>str2){
     length1=strlen(str1);
     length2=strlen(str2);
     for(int i=0;i<=length1-1;i++){
       LCS[i][0]=0;
     }
     for(int j=0;j<=length2-1;j++){
       LCS[0][j]=0;
     }
     for(int i=1;i<=length1;i++){
       for(int j=1;j<=length2;j++){
         if(str1[i-1]==str2[j-1]) {
           LCS[i][j]=LCS[i-1][j-1]+1;
         }
         else LCS[i][j]=max(LCS[i-1][j],LCS[i][j-1]);
       }
     }
     printf("%d\n",LCS[length1][length2]);
   }
 }
   return 0;
}

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

using Lint=long long;

void solve()
{
   string s,t; cin>>s>>t;
   int N=s.size(),M=t.size();
   s=' '+s; t=' '+t;
   vector<vector<int>> dp(N+1,vector<int>(M+1));
   for(int i=1;i<=N;i++) for(int j=1;j<=M;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]); }
   }

   string ans;
   int i=N,j=M;
   while(dp[i][j]>0){
      if(s[i]==t[j]){
         ans=s[i]+ans;
         i--; j--;
      }else{
         if(dp[i-1][j]>dp[i][j-1]) i--;
         else j--;
      }
   }
   // cout<<ans<<endl;
   cout<<ans.size()<<endl;
}

int main()
{
   int Q; cin>>Q;
   while(Q--){ solve(); }
   return 0;
}

C++: #include <iostream>

int max(int x, int y)
{
	return x>y ? x : y;
}

int main()
{
	std::string strq; getline(std::cin, strq);
	int q = std::stoi(strq);
	
	for (int i=0; i<q; i++) {
		std::string X; getline(std::cin, X);
		std::string Y; getline(std::cin, Y);
		
		int n = X.size();
		int m = Y.size();
		
		int** DP = new int*[n+1];
		for (int i=0; i<n+1; i++) DP[i] = new int[m+1];
	
		for (int i=0; i<n+1; i++) DP[i][0] = 0;
		for (int j=1; j<m+1; j++) DP[0][j] = 0;
	
		for (int i=1; i<n+1; i++) {
			for (int j=1; j<m+1; j++) {
				if (X[i-1] == Y[j-1]) DP[i][j] = DP[i-1][j-1] + 1;
				else DP[i][j] = max(DP[i][j-1], DP[i-1][j]);
			}
		}
		
		std::cout << DP[n][m] << std::endl;

		for (int i=0; i<n+1; i++) delete[] DP[i];
		delete[] DP;
	}
	
	return 0;
}

C++: import java.util.Scanner;

public class alds1_10 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String X = null, Y = null;
        int[][] dp = new int[1001][1001];

        int q = sc.nextInt();

        for (int i = 0; i < q; ++i) {
            X = sc.next();
            Y = sc.next();
            for (int x = 0; x < X.length(); ++x) {
                for (int y = 0; y < Y.length(); ++y) {
                    if (X.charAt(x) == Y.charAt(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];
                        }
                    }
                }
            }
            System.out.printf("%d\n", dp[X.length()][Y.length()]);
        }
    }
}

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

int main() {
    int q, max_num, now_max, start_pos, target_pos;
    char target;
    string X, Y;

    cin >> q;

    for (int i = 0; i < q; i++) {
        cin >> X >> Y;
        max_num = 0;
        for (int j = 0; j < Y.length(); j++) {
            start_pos = j;
            target = Y[start_pos];
            target_pos = 0;
            now_max = 0;
            while (start_pos < Y.length()) {
                for (int k = target_pos; k < X.length(); k++) {
                    if (target == X[k]) {
                        now_max++;
                        target = Y[start_pos];
                        target_pos = k + 1;
                        break;
                    }
                }
                start_pos++;
                target = Y[start_pos];
            }
            max_num = max(max_num, now_max);
        }
        cout << max_num << endl;
    }
}

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 b=0;b<a;b++){
    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;
}