#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T abs(T &a) {
  return a > 0 ? a : -a;
}
template <class T>
inline T min(T &a, T &b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
  return a > b ? a : b;
}
inline void read(int &x) {
  char ch;
  while ((ch = getchar()) && !(ch >= '0' && ch <= '9'))
    ;
  x = ch - '0';
  while ((ch = getchar()) && (ch >= '0' && ch <= '9')) x = x * 10 + ch - '0';
}
const int N = 300000;
char s[N];
int n, m, dt[N][4], dy[N], w[N][4], Nxt[N], Dl, wl, Za[N], Sz[N];
long long dis[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= 1; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n; j++) dt[j][i] = (s[j] == 'X');
  }
  Dl = 1;
  for (int i = 1; i <= n; i++) {
    if (!dt[i][0] && !dt[i][1])
      dy[i] = Dl, Nxt[i] = wl + 1;
    else if (dt[i][0] && dt[i][1])
      Za[i] = 1, Dl++;
    else
      w[++wl][0] = (dt[i][0] == 0), w[wl][1] = i, Nxt[i] = wl, Dl++;
  }
  for (int i = 1; i <= n; i++) Sz[i] = Sz[i - 1] + Za[i];
  for (int i = 2; i <= wl; i++)
    if (w[i][0] == w[i - 1][0])
      dis[i] = (long long)(w[i][1] - w[i - 1][1]);
    else if (w[i][1] == w[i - 1][1] + 1)
      dis[i] = (long long)1000000000;
    else
      dis[i] = (long long)(w[i][1] - w[i - 1][1] + 1);
  for (int i = 2; i <= wl; i++) dis[i] += dis[i - 1];
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    int p = x % n, q = y % n, L, R, ans = 0;
    if (!p) p = n;
    if (!q) q = n;
    if (Za[p] || Za[q]) {
      puts("-1");
      continue;
    }
    if (Sz[p] != Sz[q]) {
      puts("-1");
      continue;
    }
    if (p > q) swap(x, y), swap(p, q);
    if (dy[p] && dy[q] && dy[p] == dy[q]) {
      printf("%d\n", abs(p - q) + abs(x / (n + 1) - y / (n + 1)));
      continue;
    }
    if (dy[p]) ans += w[Nxt[p]][1] - p + (w[Nxt[p]][0] == x / (n + 1));
    if (dy[q]) ans += q - w[Nxt[q] - 1][1] + (w[Nxt[q] - 1][0] == y / (n + 1));
    L = Nxt[p];
    if (dy[q])
      R = Nxt[q] - 1;
    else
      R = Nxt[q];
    if (dis[R] - dis[L] > (long long)(1000000000)) {
      puts("-1");
      continue;
    }
    ans += int(dis[R] - dis[L]);
    if (ans >= 1000000000 / 2)
      puts("-1");
    else
      printf("%d\n", ans);
  }
}
