#include <bits/stdc++.h>
using namespace std;
long long ccs(string s, string t) {
  long long n1 = s.length();
  long long n2 = t.length();
  long long dp[n1 + 1][n2 + 1];
  for (long long i = 0; i <= n1; i++) {
    for (long long j = 0; j <= n2; j++) {
      dp[i][j] = 0;
    }
  }
  for (long long i = 1; i <= n1; i++) {
    for (long long j = 1; j <= n2; j++) {
      if (s[i - 1] == t[j - 1])
        dp[i][j] =
            (1 + (dp[i][j - 1] % 1000000007 + dp[i - 1][j] % 1000000007) %
                     1000000007) %
            1000000007;
      else
        dp[i][j] =
            (dp[i][j - 1] % 1000000007 +
             (dp[i - 1][j] % 1000000007 - dp[i - 1][j - 1] % 1000000007) %
                 1000000007) %
            1000000007;
    }
  }
  return dp[n1][n2] % 1000000007;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  string a = "", b = "";
  for (long long x = 0; x < n; x++) {
    char c;
    cin >> c;
    a = a + c;
  }
  for (long long x = 0; x < m; x++) {
    char c;
    cin >> c;
    b = b + c;
  }
  cout << a << " " << b << "\n";
  cout << (ccs(a, b) + 1) % 1000000007;
  return 0;
}
