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 x, y;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x >> y;
        cout << lcs(x, y) << 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 <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> S(2*n);
    for (auto i = 0; i < 2*n; i++)
    {
        string s;
        cin >> s;
        S[i] = s;
    }

    for (auto i = 0; i < 2*n; i += 2)
    {
        string x = S[i];
        string y = S[i + 1];
        int sizex = x.size();
        int sizey = y.size();

        vector<vector<int>> m(sizex+1, vector<int>(sizey+1));

        for (auto j = 0; j < sizex+1; j++)
        {                
                m[j][0] = 0;   
        }

        for (auto j = 0; j < sizey+1; j++)
        {
                m[0][j] = 0;
        }


        for (auto j = 1; j < sizex+1; j++)
        {
            for (auto k = 1; k < sizey+1; k++)
            {
                if(x[j-1] == y[k-1]){
                    m[j][k] = m[j - 1][k - 1] + 1;
                }else{
                    m[j][k] = max(m[j - 1][k], m[j][k - 1]);
                }
            }
        }

        cout << m[sizex][sizey] << endl;

    }   
    
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int 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;
    X=' '+ X;
    Y=' '+ Y;
    
    for (int i=0; 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(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 << lsc(s1,s2) << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>

#define MAX 1010
#define max(a,b) ((a<b)?b:a)

char s[MAX], t[MAX];
int dp[MAX][MAX],path[MAX][MAX];

int LCS() {
  int n = strlen(s);
  int m = strlen(t);
  memset(dp,0,sizeof dp);
  int i,j,maxi=0;
  for(i=0;i<n;i++) {
    for(j=0;j<m;j++) {
      if( i ) dp[i][j] = max(dp[i][j],dp[i-1][j]);
      if( j ) dp[i][j] = max(dp[i][j],dp[i][j-1]);
      if( s[i] == t[j] ) {
	dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1);
	maxi = max(maxi,dp[i+1][j+1]);
      }
    }
  }
  return maxi;
}

int main() {
  int n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++) {
  scanf(" %s",&s[0]);
  scanf(" %s",&t[0]);
  printf("%d\n",LCS());
  }
  return 0;
}

C++: //
// Created by 李青坪 on 2018/10/29.
//

#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>

#define MAXN 150
#define MAXLEN 1000
using namespace std;

int c[MAXLEN+1][MAXLEN+1];

int getSubsequence(string x, string y){
    int i = 0, j = 0;
    while (i <= x.length()){
        while (j <= y.length()){
            if (i == 0 || j ==0){
                c[i][j] = 0;
            } else if (x[i-1] == y[j-1]){
                c[i][j] = c[i-1][j-1] + 1;
            } else if (x[i-1] != y[j-1]){
                c[i][j] = max(c[i-1][j], c[i][j-1]);
            }
            ++j;
        }
        ++i;
        j = 0;
    }
    return c[x.length()][y.length()];
}

int main(){
    int n;
    scanf("%d", &n);
    string x, y;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        printf("%d\n", getSubsequence(x, y));
    }

}
/*
3
abcbdab
bdcaba
abc
abc
abc
bc
 */

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 = 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 <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#pragma warning(disable : 4996)

#define MAX_L 1000

int DP[MAX_L+1][MAX_L+1];

int max(int a, int b) {
	if (a > b) return a;
	return b;
}

int main(void) {
	int n;
	scanf("%d", &n);
	char X[MAX_L + 1];
	char Y[MAX_L + 1];
	for (int i = 0; i < n; ++i) {
		scanf("%s", &X[0]);
		scanf("%s", &Y[0]);
		int xl = strlen(X);
		int yl = strlen(Y);

		for (int j = 0; j < yl; ++j) {
			for (int i = 0; i < xl; ++i) {
				if (X[i] == Y[j]) {
					DP[j + 1][i + 1] = DP[j][i] + 1;
				}
				else {
					DP[j + 1][i + 1] = max(DP[j][i + 1], DP[j + 1][i]);
				}
			}
		}
		printf("%d\n", DP[yl][xl]);

	}

	return 0;
}