#include <bits/stdc++.h>
using namespace std;
long long powmod(long long x, long long y, long long p) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % p;
    x = x * x % p;
    y >>= 1;
  }
  return ans;
}
long long F[200010], Fac[200010], Rev[200010], rev[1048576], r[200010];
int V[200010], st = 0;
vector<long long> C[21], rC[21];
long long P, g;
unsigned long long X[1048576], Y[1048576];
bool npr[50000010];
void DFT(unsigned long long *X, int t) {
  for (int i = 0; i < t; i++)
    for (int j = 0; j < (1 << t); j += (1 << i + 1))
      for (int k = 0; k < (1 << i); k++) {
        long long A = X[j + k], B = X[j + k + (1 << i)] * C[i + 1][k] % P;
        X[j + k] = A + B;
        X[j + k + (1 << i)] = A - B + P;
      }
  for (int i = 0; i < (1 << t); i++) X[i] %= P;
}
void pr(int o) {
  for (int i = 1; i <= o; i++) {
    C[i].resize(1 << i), C[i][0] = 1;
    long long w = powmod(g, (P - 1) >> i, P);
    for (int j = 1; j < (1 << i); j++) C[i][j] = C[i][j - 1] * w % P;
    rC[i] = C[i];
    reverse(rC[i].begin() + 1, rC[i].end());
  }
}
long long getori() {
  for (int g = 2;; g++) {
    assert(powmod(g, P - 1, P) == 1);
    int flag = 0;
    for (int i = 2; i * i <= P - 1; i++)
      if ((P - 1) % i == 0) {
        if (powmod(g, i, P) == 1 || powmod(g, (P - 1) / i, P) == 1) {
          flag = 1;
          break;
        }
      }
    if (!flag) return g;
  }
}
int n, m;
char ch1[1048576], ch2[1048576];
int XX[22][1058571];
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s", ch1 + 1);
  scanf("%s", ch2 + 1);
  for (int o = 0; o < 22; o++)
    for (int i = 1; i <= n; i++)
      XX[o][(i - 1) & ((1 << o) - 1)] =
          ((int)XX[o][(i - 1) & ((1 << o) - 1)] + (ch1[i] - ch2[i]));
  for (int i = 2; i <= 100000; i++)
    if (!npr[i])
      for (int j = i + i; j < 50000000; j += i) npr[j] = 1;
  for (P = m;; P++)
    if (!npr[P]) {
      long long tmp = P - 1;
      int o = 0, s = tmp & -tmp;
      while ((1 << o) != s) o++;
      if ((1 << o) <= P / 400) continue;
      o = min(o, 20);
      g = getori();
      pr(o);
      for (int i = 0; i < (1 << o); i++) X[i] = (XX[o][i] % P + P) % P;
      for (int i = 1; i < (1 << o); i++)
        rev[i] = rev[i / 2] / 2 + (i & 1) * (1 << o - 1);
      for (int i = 0; i < (1 << o); i++)
        if (rev[i] > i) swap(X[i], X[rev[i]]);
      DFT(X, o);
      tmp = 1;
      s = powmod(g, (P - 1) >> o, P);
      for (int i = 0; i < (1 << o); i++) {
        if (tmp != 1 && tmp != P - 1 && X[i] % P == 0) {
          printf("%lld %lld\n", P, tmp);
          return 0;
        }
        tmp = tmp * s % P;
      }
    }
  return 0;
}
