Go: package main

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

func max(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = " " + s1 , " " + s2
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					c[i][j] = c[i-1][j-1] + 1
				} else {
					c[i][j] = max(c[i-1][j], c[i][j-1])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

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;
    int i,j;

    X = ' ' + X;
    Y = ' ' + Y;

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

    for(i = 1 ;i <= m;i++)
    {
        for(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 <iostream>
#include <string>
#include <algorithm>
using namespace std;

constexpr int N=1000;

int lcs(string x, string y){
   int m=x.size();
   int n=y.size();
   int c[N+1][N+1];
   
   for(int i=0; i<N; i++)
      for(int j=0; j<N; j++)
         c[i][j]=0;
   int ans=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 c[i][j]=max(c[i-1][j], c[i][j-1]);
         ans=c[i][j];
      }
   }
   return ans;
}

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<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define INFTY 2000000001
#define MAX 1001

char str[150][2][MAX];
int n = 0;
int c[MAX][MAX];

void lcs(int i) {
  int len0 = strlen(str[i][0]);
  int len1 = strlen(str[i][1]);
  for (int j = 0; j < len0; j++) c[j][0] = 0;
  for (int j = 0; j < len1; j++) c[0][j] = 0;
  for (int m = 0; m < len0; m++) {
    for (int n = 0; n < len1; n++) {
      if (str[i][0][m] == str[i][1][n]) {
        c[m+1][n+1] = c[m][n] + 1;
      } else if (c[m+1][n] >= c[m][n+1]) {
        c[m+1][n+1] = c[m+1][n];
      } else {
        c[m+1][n+1] = c[m][n+1];
      }
    }
  }
}

int main() {
  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) {
    scanf("%s", str[i][0]);
    scanf("%s", str[i][1]);
  }

  for (int i = 0; i < n; i++) {
    lcs(i);
    printf("%d\n", c[strlen(str[i][0])][strlen(str[i][1])]);
  }

  return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int q; cin>>q;
	for(int i=0;i<q;++i){
		string x,y; cin>>x>>y;
		vector<vector<int>>dp(y.size()+1,vector<int>(x.size()+1));
		for(auto&j:dp)j.at(0)=0; for(auto&j:dp.at(0))j=0;
		for(int j=0;j<y.size();++j){
			for(int k=0;k<x.size();++k){
				if(y.at(j)==x.at(k))dp.at(j+1).at(k+1)=dp.at(j).at(k)+1;
				else dp.at(j+1).at(k+1)=max({dp.at(j).at(k),dp.at(j).at(k+1),dp.at(j+1).at(k)});
			}
		}
		cout<<dp.back().back()<<"\n"s;
	}
}

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

#define MAX 150
#define MAXL 1000

int C[MAXL+1][MAXL+1];

int lec(string X,string Y)
{
    int XL = X.length();
    int YL = Y.length();
    for(int i=0;i<=XL;i++)
        C[i][0] = 0;
    for(int i=0;i<=YL;i++)
        C[0][i] = 0;
    for(int i=0;i<=XL;i++)
    {
        for(int j=0;j<=YL;j++)
        {
            if(X[i+1]==Y[j+1])
            {
                C[i+1][j+1] = C[i][j]+1;
            }
            else if(C[i][j+1] > C [i+1][j])
            {
                C[i+1][j+1] = C[i-1][j+1];
            }else{
                C[i+1][j+1] = C[i+1][j];
            }
        }
    }
    return C[XL][YL];
}

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

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

using namespace std;

static const int N = 1000;
static int c[N + 1][N + 1] = {};

static int lcs(string& X, string& Y) {
  const size_t m(X.size());
  const size_t n(Y.size());

  int lcs = 0;
  
  for (size_t i = 1; i <= m; i++) {
    for (size_t 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]);
      }
      lcs = max(lcs, c[i][j]);
    }
  }
  return lcs;
}

int main() {
  int n;
  cin >> n;

  string X, Y;
  for (int i = 0; i < n; i++) {
    cin >> X;
    cin >> Y;
    cout << lcs(X, Y) << endl;
  }
 
  return 0;
}