Buggy python submission (verdict: Runtime Error):
q = int(input())

def Longest_Common(q) :
    X = raw_input()
    Y = raw_input()
    dp = [ [0 for i in range( len(X) )] for j in range( len(Y) )] #???X??????Y?????????????????????
    
    for j in range( len(Y) ):
        if Y[j] == X[0] :
            dp[j][0] += 1
        if( j+1 <= len(Y) - 1 ) :
            dp[j+1][0] = dp[j][0]

    for i in range( 1,len(X) ):
        if X[i] == Y[0] :
            dp[0][i] += 1
        if( i+1 <= len(X) - 1 ) :
            dp[i+1][0] = dp[i][0]
        
    for i in range( 1,len(X) ): 
        for j in range( 1,len(Y) ):
            if X[i] == Y[j] : dp[j][i] = max( dp[j-1][i-1], dp[j-1][i], dp[j][i-1]) + 1 
            else : dp[j][i] = max( dp[j-1][i-1], dp[j-1][i], dp[j][i-1])
                
    print dp[ len(Y)-1 ][ len(X)-1 ]    
    
    if( q == 1 ) :
        return
    else :
        Longest_Common(q-1)
        
Longest_Common(q)

Fixed submission:
def solve():
    seq1 = raw_input()
    seq2 = raw_input()
  
    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]
  
n = input()
for i2 in range(n):
    print solve()

Buggy python submission (verdict: Runtime Error):

q = int(input())

def Longest_Common(q) :
    X = raw_input()
    Y = raw_input()
    dp = [ [0 for i in range( len(X) )] for j in range( len(Y) )] #???X??????Y?????????????????????
    
    for j in range( len(Y) ):
        if Y[j] == X[0] :
            dp[j][0] += 1
        if( j+1 <= len(Y) - 1 ) :
            dp[j+1][0] = dp[j][0]

    for i in range( 1,len(X) ):
        if X[i] == Y[0] :
            dp[0][i] += 1
        if( i+1 <= len(X) - 1 ) :
            dp[0][i+1] = dp[0][i+1]
        
    for i in range( 1,len(X) ): 
        for j in range( 1,len(Y) ):
            if X[i] == Y[j] : dp[j][i] = max( dp[j-1][i-1], dp[j-1][i], dp[j][i-1]) + 1 
            else : dp[j][i] = max( dp[j-1][i-1], dp[j-1][i], dp[j][i-1])
                
    print dp[ len(Y)-1 ][ len(X)-1 ]    
    
    if( q == 1 ) :
        return
    else :
        Longest_Common(q-1)
        
Longest_Common(q)

Fixed submission:
def solve():
    seq1 = raw_input()
    seq2 = raw_input()
  
    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]
  
n = input()
for i2 in range(n):
    print solve()

Buggy python submission (verdict: Runtime Error):
q = int(input())

def Longest_Common(q) :
    X = raw_input()
    Y = raw_input()
    dp = [ [0 for i in range( len(X) )] for j in range( len(Y) )] #???X??????Y?????????????????????
    
    for j in range( len(Y) ):
        if Y[j] == X[0] :
            dp[j][0] += 1
        if( j+1 <= len(Y) - 1 ) :
            dp[j+1][0] = dp[j][0]

    for i in range( 1,len(X) ):
        if X[i] == Y[0] :
            dp[0][i] += 1
        if( i+1 <= len(X) - 1 ) :
            dp[0][i+1] = dp[0][i+1]
        
    for i in range( 1,len(X) ): 
        for j in range( 1,len(Y) ):
            if X[i] == Y[j] : dp[j][i] = max( dp[j-1][i-1], dp[j-1][i], dp[j][i-1]) + 1 
            else : dp[j][i] = max( dp[j-1][i-1], dp[j-1][i], dp[j][i-1])
                
    print dp[ len(Y)-1 ][ len(X)-1 ]    
    
    if( q == 1 ) :
        return
    else :
        Longest_Common(q-1)
        
Longest_Common(q)

Fixed submission:
def solve():
    seq1 = raw_input()
    seq2 = raw_input()
  
    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]
  
n = input()
for i2 in range(n):
    print solve()