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<cstdio>
using namespace std;



int lcs(string x, string y){

  int m = x.length();
  int n = y.length();

  int c[m + 1][n + 1];

  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 - 1] == y[j - 1]){
        c[i][j] = c[i - 1][j - 1] + 1;
      }
      else if(c[i - 1][j] > c[i][j - 1]){
        c[i][j] = c[i - 1][j];
      }
      else{
        c[i][j] = c[i][j - 1];
      }
  //    cout << "c" << i << j << c[i][j] << endl;
    }

  }

  return c[m][n];
}

int main(){

  int q;

  string x, y;

  cin >> q;

  for(int i = 0; i < q; i++){
    cin >> x;
    cin >> y;
    cout << lcs(x, y) << endl;
  }



  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
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 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<cmath>
using namespace std;

int main(void){
  string st1, st2;
  int q, val[151][151];

  cin >> q;

  for(int i=0; i<q; i++){
    cin>>st1;
    cin>>st2;

    for(int j=0; j<=st1.length(); j++){
      for(int k=0; k<=st2.length(); k++){

	if(j==0 || k==0) val[j][k] = 0;
	else{

	  if(st1[j-1] == st2[k-1]){
	    val[j][k] = max(val[j-1][k], val[j][k-1]+1);
	  }else{
	    val[j][k] = max(val[j-1][k], val[j][k-1]);
	  }
	}

	if(val[j][k] >= st1.length() || val[j][k] >= st1.length()){
	  val[j][k] = min(st1.length(), st2.length());
	}
      }
    }

    for(int j=0; j<=st1.length(); j++){
      for(int k=0; k<=st2.length(); k++){
	cout << val[j][k] << " ";
      }
      cout << "\n";
    }

    cout << val[st1.length()][st2.length()] << "\n";
  }

  return 0;
}

C++: #include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;

//--------------
//#define DEBUG
//--------------

#ifdef DEBUG
	#define debugprint(x) cout<<x<<" "
	#define debugendl cout<<endl
	#define debug(x) x
#else
	#define debugprint(x)
	#define debugendl
	#define debug(x)
#endif

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	zahyo operator*(int t){
		zahyo temp;
		temp.x=this->x*t;
		temp.y=this->y*t;
		return temp;
	}
	zahyo operator%(int t){
		zahyo temp(this->x%t,this->y%t);
		return temp;
	}
	zahyo operator/(int t){
		zahyo temp(this->x/t,this->y/t);
		return temp;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

bool IsInBoard(int x,int maxx, int y,int maxy){
	if(x>=0 and x<maxx and y>=0 and y<maxy){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		string x,y;
		cin>>x>>y;
		int dp[1001][1001]={};
		for(int j=1;j<=x.size();j++){
			for(int k=1;k<=y.size();k++){
				int same=0;
				if(x[j-1]==y[k-1]){
					same=1;
				}
				dp[j][k]=max(dp[j-1][k-1]+same,max(dp[j-1][k],dp[j][k-1]));
			}
		}
		cout<<dp[x.size()][y.size()]<<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 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;
}