Go: package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vi> dp(n+2, vi(m+2));
    rep(i, n+1) rep(j, m+1) {
        // cout << i << " " << j << endl;
        if(i >= n) {
            chmax(dp[i][j+1], dp[i][j]);
        }
        else if(j >= m) {
            chmax(dp[i+1][j], dp[i][j]);
        }
        else if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
        else {
            chmax(dp[i+1][j], dp[i][j]);
            chmax(dp[i][j+1], dp[i][j]);
        }
    }
    cout << dp[n][m] << '\n';
    // rep(i, n+2) {
    //     rep(j, m+2) {
    //         cout << " " << dp[i][j];
    //     }
    //     cout << endl;
    // }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, n) solve();
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int dp[1005][1005] = { 0 };
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string x, y;
		cin >> x >> y;
		for (int j = 0; j < 1005; j++)
			for (int k = 0; k < 1005; k++) dp[j][k] = 0;
		for (int j = 1; j <= x.size(); j++) {
			for (int k = 1; k <= y.size(); k++) {
				dp[j][k] = max(dp[j][k - 1], dp[j - 1][k]);
				if (x[j - 1] == y[k - 1]) {
					dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + 1);
				}
			}
		}
		cout << dp[x.size()][y.size()] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int dp[2010][2010];

int LCS(string s, string t) {
    rep(i, s.size() + 10) dp[i][0] = 0;
    rep(i, t.size() + 10) dp[0][i] = 0;

    for(int i = 1; i <= s.size(); i++) {
        for(int j = 1; j <= t.size(); j++) {
            dp[i][j] = 0;
            chmax(dp[i][j], dp[i - 1][j]);
            chmax(dp[i][j], dp[i][j - 1]);

            if(s[i - 1] == t[j - 1]) {
                chmax(dp[i][j], dp[i - 1][j - 1] + 1);
                //cout << "foo" << endl;
            }
        }
    }
    
    return dp[s.size()][t.size()];
}

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int q;
    cin >> q;
    rep(i, q) {
        string s, t;
        cin >> s >> t;
        cout << LCS(s, t) << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespce std;

int main()
{
	int n,i;
	int a[25];
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>

using namespace std;

class LCSubseq
{
public:
  int solve( const string x, const string y );
};

int LCSubseq::solve( const string x, const string y )
{
  vector<vector<int>> dp( 1 + x.size(), vector<int>( 1 + y.size(), 0 ) );
  
  for ( auto i = 0; i < (int)x.size(); ++i )
    for( auto j = 0; j < (int)y.size(); ++j )
      {
        if ( x[i] == y[j] )
          dp[i+1][j+1] = dp[i][j] + 1;
        else
          dp[i+1][j+1] = max( dp[i+1][j], dp[i][j+1] );
      }
  
  cout << dp[x.size()][y.size()] << endl;
  
  return 0;
}

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

  LCSubseq l;

  string x, y;
  
  for ( auto i = 0; i < n; ++i )
    {
      cin >> x;
      cin >> y;
      l.solve( x, y );
    }
  
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
static const int N=1000;
/*int max(int a,int b){
    if(a>b)return a;else return b;
}*/
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 <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define ALLA(a) a,a+a.size();
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;


int lcs(string X,string Y){
  int m = X.length();
  int n = Y.length();
  int c[m+1][n+1];
  int maxl = 0;
  //0文字目を追加1-indexed
  X = ' ' + X;
  Y = ' ' + Y;
  //0文字目と一致するはずがないので0を入れる
  REP(i,m + 1){
    c[i][0] = 0;
  }
  REP(j,n + 1){
    c[0][j] = 0;
  }

  //Xの1文字ずつループ
  FOR(i,1,m+1){
    //Yの1文字ずつループ
    FOR(j,1,n+1){
      if(X[i] == Y[j]){
	/*XとYで一致する文字を見つけた
	  ⇛ その文字が出るまでのLCSに1を足す(新たな文字)*/
	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 (){
  int n;
  string x,y;
  while (cin >> n){
    REP(i,n){
      cin >> x >> y;
      cout << lcs(x,y) << endl;
    }
    
  }
  return 0;
}