#include <bits/stdc++.h>
using namespace std;
const int N = 200001, inf = 0x3f3f3f3f;
int n, m, M, mp[3][N << 3];
char ch[N];
struct data {
  int d1, d2, d3, d4;
} node[N << 3];
data merge(data a, data b) {
  data tmp;
  tmp.d1 = min(inf, min(a.d1 + b.d1, a.d2 + b.d3) + 1);
  tmp.d2 = min(inf, min(a.d1 + b.d2, a.d2 + b.d4) + 1);
  tmp.d3 = min(inf, min(a.d3 + b.d1, a.d4 + b.d3) + 1);
  tmp.d4 = min(inf, min(a.d3 + b.d2, a.d4 + b.d4) + 1);
  return tmp;
}
void build() {
  M = 1;
  while (M - 2 < n) M <<= 1;
  for (int i = 1; i <= 2; ++i)
    for (int j = 0; j <= M; ++j) mp[i][j] = 1;
  for (int i = 1; i <= 2; ++i) {
    scanf("%s", ch);
    for (int j = 1; j <= n; ++j)
      if (ch[j - 1] == 'X') mp[i][j] = 0;
  }
  for (int i = 0; i < M; ++i) {
    int v = i + M;
    node[v].d1 = node[v].d2 = node[v].d3 = node[v].d4 = inf;
    if (mp[1][i]) node[v].d1 = 0;
    if (mp[2][i]) node[v].d4 = 0;
    if (mp[1][i] && mp[2][i]) node[v].d2 = node[v].d3 = 1;
  }
  for (int i = M - 1; i > 0; --i)
    node[i] = merge(node[i << 1], node[i << 1 | 1]);
}
data query(int x, int y) {
  data lch = (data){0, 1, 1, 0}, rch = (data){0, 1, 1, 0};
  for (x += M - 1, y += M + 1; x ^ y ^ 1; x >>= 1, y >>= 1) {
    if (~x & 1) lch = merge(lch, node[x ^ 1]);
    if (y & 1) rch = merge(node[y ^ 1], rch);
  }
  return merge(lch, rch);
}
int ask(int x, int y) {
  int a = (x - 1) % n + 1, b = (y - 1) % n + 1;
  if (a > b) {
    swap(x, y);
    swap(a, b);
  }
  data tmp = query(a, b);
  if (x <= n && y <= n) return tmp.d1;
  if (x <= n && y > n) return tmp.d2;
  if (x > n && y <= n) return tmp.d3;
  if (x > n && y > n) return tmp.d4;
}
int main() {
  scanf("%d%d", &n, &m);
  build();
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int ans = ask(x, y);
    if (ans < inf)
      printf("%d\n", ans - 2);
    else
      printf("-1\n");
  }
}
