#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 998244353;
template <typename T>
void cmin(T &x, T y) {
  if (y < x) x = y;
}
template <typename T>
void cmax(T &x, T y) {
  if (y > x) x = y;
}
long long qpow(long long x, long long n, long long mod = MOD) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
const int MAXN = 1e6 + 3e5;
int p[MAXN + 5], ptop;
int pm[MAXN + 5], pk[MAXN + 5];
void sieve(int n) {
  pm[1] = 1, pk[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!pm[i]) p[++ptop] = i, pm[i] = i, pk[i] = i;
    for (int j = 1; j <= ptop; ++j) {
      int t = i * p[j];
      if (t > n) break;
      pm[t] = p[j];
      if (i % p[j])
        pk[t] = pk[p[j]];
      else {
        pk[t] = pk[i] * p[j];
        break;
      }
    }
  }
}
namespace Solver {
void InitOnce() {
  sieve(MAXN);
  int t;
}
int n, m, D;
char s[200005], t[200005];
long long ns[200005], nt[200005];
bool hashSame(int P, int R) {
  long long hash1 = 0, hash2 = 0;
  for (int i = 1; i <= n; ++i) {
    hash1 = (hash1 * R + s[i]) % P;
    hash2 = (hash2 * R + t[i]) % P;
  }
  return hash1 == hash2;
}
mt19937 rnd(19260817);
void Read() {
  int res = scanf("%d%d", &n, &m);
  if (res == -1) exit(0);
  scanf("%s%s", s + 1, t + 1);
}
void reduceLength(int L) {
  int cL = min(n, L);
  for (int i = 1; i <= cL; ++i) {
    ns[i] = 0;
    for (int j = i; j <= n; j += L) ns[i] += s[j];
    nt[i] = 0;
    for (int j = i; j <= n; j += L) nt[i] += t[j];
  }
}
bool solveLPR(int L, int P, int R) {
  int cL = min(n, L);
  long long hash1 = 0, hash2 = 0;
  for (int i = 1; i <= cL; ++i) {
    hash1 = (hash1 * R + ns[i]) % P;
    hash2 = (hash2 * R + nt[i]) % P;
  }
  return hash1 == hash2;
}
bool solveLP(int L, int P) {
  for (int t = 198; t; --t) {
    int r = rnd() % P;
    if (r == 1 || r == P - 1) continue;
    if (qpow(r, L, P) == 1) {
      int R = 1, D = (P - 1) / L;
      for (int k = 1; k <= L; ++k) {
        R = 1LL * R * r % P;
        if (R == 1 || R == P - 1) continue;
        if (solveLPR(L, P, R)) {
          printf("%d %d\n", P, R);
          return 1;
        }
      }
    }
  }
  return 0;
}
void Solve() {
  rnd.seed(time(0));
  reverse(s + 1, s + 1 + n);
  reverse(t + 1, t + 1 + n);
  for (int L = 1; L <= 1000; ++L) {
    reduceLength(L);
    for (int j = lower_bound(p + 1, p + 1 + ptop, m / L) - p; j <= ptop; ++j) {
      long long P = 1LL * L * p[j] + 1;
      if (P > MAXN) break;
      if (rnd() % 4096 == 0) break;
      if (m <= P && pm[P] == P) {
        if (solveLP(L, P)) return;
      }
    }
  }
  puts("-1");
  return;
}
}  // namespace Solver
int main() {
  Solver::InitOnce();
  while (true) {
    Solver::Read();
    Solver::Solve();
  }
  return 0;
}
