#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 7;
int N, M;
char mp[3][maxN];
struct node {
  int dp[4];
  node() { memset(dp, 0x3f3f3f3f, sizeof(dp)); }
  friend node operator+(node e1, node e2) {
    node ans;
    ans.dp[0] =
        min(0x3f3f3f3f, min(e1.dp[0] + e2.dp[0] + 1, e1.dp[1] + e2.dp[2] + 1));
    ans.dp[1] =
        min(0x3f3f3f3f, min(e1.dp[1] + e2.dp[3] + 1, e1.dp[0] + e2.dp[1] + 1));
    ans.dp[2] =
        min(0x3f3f3f3f, min(e1.dp[2] + e2.dp[0] + 1, e1.dp[3] + e2.dp[2] + 1));
    ans.dp[3] =
        min(0x3f3f3f3f, min(e1.dp[2] + e2.dp[1] + 1, e1.dp[3] + e2.dp[3] + 1));
    return ans;
  }
} tree[maxN << 2];
inline void pushup(int rt) { tree[rt] = tree[rt << 1] + tree[rt << 1 | 1]; }
void buildTree(int rt, int l, int r) {
  if (l == r) {
    if (mp[1][l] == '.') tree[rt].dp[0] = 0;
    if (mp[2][l] == '.') tree[rt].dp[3] = 0;
    if (mp[1][l] == '.' && mp[2][l] == '.') tree[rt].dp[1] = tree[rt].dp[2] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  buildTree(rt << 1, l, mid);
  buildTree(rt << 1 | 1, mid + 1, r);
  pushup(rt);
}
node query(int rt, int l, int r, int ql, int qr) {
  if (ql <= l && qr >= r) return tree[rt];
  int mid = (l + r) >> 1;
  if (qr <= mid)
    return query(rt << 1, l, mid, ql, qr);
  else if (ql > mid)
    return query(rt << 1 | 1, mid + 1, r, ql, qr);
  else
    return query(rt << 1, l, mid, ql, qr) +
           query(rt << 1 | 1, mid + 1, r, ql, qr);
}
int output(int x, int y) {
  int u = x > N ? (x - N) : x, v = y > N ? (y - N) : y;
  if (u > v) {
    swap(u, v);
    swap(x, y);
  }
  node ans = query(1, 1, N, u, v);
  if (x <= N && y <= N)
    return ans.dp[0];
  else if (x > N && y <= N)
    return ans.dp[2];
  else if (x <= N && y > N)
    return ans.dp[1];
  else
    return ans.dp[3];
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= 2; i++) scanf("%s", mp[i] + 1);
  buildTree(1, 1, N);
  for (int i = 1, x, y; i <= M; i++) {
    scanf("%d%d", &x, &y);
    int ans = output(x, y);
    printf("%d\n", ans < 0x3f3f3f3f ? ans : -1);
  }
  return 0;
}
