1. 
/**
* FWP, Ausgew¤hlte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11775 - Unique Story
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=117&page=show_problem&problem=2875
*
* @author Evgeni Pavlidis
* @version 1.0, 06/01/2010
*
* Method : Dynamic Programming - all common subsequences
* Status : Accepted
* Runtime: 1.176
*/


import java.io.*;
import java.util.*;
import java.util.regex.*;

class Main {

private static final int MOD = 10000007;

// all common subsequences
private static int acs(String[] a, String[] b)
{
int m = a.length;
int n = b.length;
int[][] dp = new int[m+1][n+1];

for(int i = 0; i <= m; i++)
dp[i][0] = 1;

for(int j = 0; j <= n; j++)
dp[0][j] = 1;

for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++)
if(a[i-1].equals(b[j-1]))
dp[i][j] = (2*dp[i-1][j-1]) % MOD;
else
dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % MOD;

return (dp[m][n] == 0)? 0 : dp[m][n]-1;
}


public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int output;
String[] a,b;
String input;

int testCases = Integer.parseInt(reader.readLine());
for(int t = 1; t <= testCases; t++)
{
input = reader.readLine().replaceAll("([A-Z][0-9]*)","$1 ");
a = input.trim().split("[ ]+");
input = reader.readLine().replaceAll("([A-Z][0-9]*)","$1 ");
b = input.trim().split("[ ]+");

int result = 0;
int power = 1;

for(int i = 0; i < a.length; i++)
power = (power << 1) % MOD;
result += (power-1) % MOD;

power = 1;
for(int i = 0; i < b.length; i++)
power = (power << 1) % MOD;
result += (power-1) % MOD;

int acs = acs(a,b);

result = (((result - 2*acs(a,b)) % MOD) + MOD) % MOD;

System.out.println("Case " + t + ": " + result);
}
}
}