#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int T = 4 * N + 5;
const int inf = 0x3f3f3f3f;
int n, m, u, v;
char s[3][N];
struct node {
  int d0, d1, d2, d3;
} t[T];
node pushup(node ls, node rs) {
  node ret;
  ret.d0 = min(inf, min(ls.d0 + rs.d0 + 1, ls.d1 + rs.d2 + 1));
  ret.d1 = min(inf, min(ls.d0 + rs.d1 + 1, ls.d1 + rs.d3 + 1));
  ret.d2 = min(inf, min(ls.d2 + rs.d0 + 1, ls.d3 + rs.d2 + 1));
  ret.d3 = min(inf, min(ls.d3 + rs.d3 + 1, ls.d2 + rs.d1 + 1));
  return ret;
}
void build(int rt, int l, int r) {
  if (l == r) {
    t[rt].d0 = t[rt].d1 = t[rt].d2 = t[rt].d3 = inf;
    if (s[1][l] == '.') t[rt].d0 = 0;
    if (s[2][l] == '.') t[rt].d3 = 0;
    if (s[1][l] == '.' && s[2][l] == '.') t[rt].d1 = t[rt].d2 = 1;
    return;
  }
  int mid = l + r >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  t[rt] = pushup(t[rt << 1], t[rt << 1 | 1]);
}
node ask(int rt, int l, int r, int L, int R) {
  if (L <= l && R >= r) return t[rt];
  int mid = l + r >> 1;
  if (R <= mid) return ask(rt << 1, l, mid, L, R);
  if (L > mid) return ask(rt << 1 | 1, mid + 1, r, L, R);
  return pushup(ask(rt << 1, l, mid, L, R), ask(rt << 1 | 1, mid + 1, r, L, R));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> s[i][j];
    }
  }
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    int a = u, b = v;
    if (a > n) a -= n;
    if (b > n) b -= n;
    if (a > b) {
      swap(a, b);
      swap(u, v);
    }
    node ret = ask(1, 1, n, a, b);
    int ans;
    if (u <= n && v <= n) ans = ret.d0;
    if (u <= n && v > n) ans = ret.d1;
    if (u > n && v <= n) ans = ret.d2;
    if (u > n && v > n) ans = ret.d3;
    if (ans < inf)
      printf("%d\n", ans);
    else
      printf("-1\n");
  }
  return 0;
}
