#include <bits/stdc++.h>
using namespace std;
struct bcj {
  int A[200005 * 2 + 3];
  void clear(int n) {
    for (int i = 1; i <= n; i++) A[i] = i;
  }
  int quest(int x) {
    if (x == A[x]) return x;
    A[x] = quest(A[x]);
    return A[x];
  }
  void update(int x, int y) {
    x = quest(x), y = quest(y);
    A[x] = y;
  }
} V;
int A[200005][2];
int F[200005][2];
int S[200005 * 2], cnt;
int n, m;
int erfen(int x) {
  int left = 0, right = cnt + 1;
  while (left < right - 1) {
    int mid = (left + right) / 2;
    if (S[mid] % (n + 1) > x)
      right = mid;
    else
      left = mid;
  }
  return right;
}
int main() {
  scanf("%d%d", &n, &m);
  char str[200005];
  scanf("%s", str);
  for (int i = 1; i <= n; i++) A[i][0] = str[i - 1] == '.' ? 1 : 0;
  scanf("%s", str);
  for (int i = 1; i <= n; i++) A[i][1] = str[i - 1] == '.' ? 1 : 0;
  for (int i = 1; i <= n; i++) {
    if (!A[i][0]) S[++cnt] = i;
    if (!A[i][1]) S[++cnt] = i + n + 1;
  }
  memset(F, 0x7f, sizeof(F));
  V.clear(n * 2 + 3);
  A[0][0] = A[0][1] = 1;
  F[0][0] = 0, F[0][1] = 1;
  V.update(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    if (A[i][0] == 1) {
      F[i][0] = min(
          min(F[i - 1][0] + 1, (A[i][1] == 1 ? F[i - 1][1] + 2 : 0x7f7f7f7f)),
          0x7f7f7f7f);
    }
    if (A[i][1] == 1) {
      F[i][1] = min(
          min(F[i - 1][1] + 1, (A[i][0] == 1 ? F[i - 1][0] + 2 : 0x7f7f7f7f)),
          0x7f7f7f7f);
    }
    if (A[i][0] == 1) {
      if (F[i][0] == 0x7f7f7f7f) {
        F[i][0] = 0;
      } else
        V.update(i, A[i - 1][0] == 1 ? i - 1 : i + n);
    }
    if (A[i][1] == 1) {
      if (F[i][1] == 0x7f7f7f7f) {
        if (A[i][0] == 1)
          F[i][1] = 1;
        else
          F[i][1] = 0;
      } else
        V.update(i + n + 1, A[i - 1][1] == 1 ? i + n : i - 1);
      if (A[i][0] == 1) V.update(i + n + 1, i);
    }
  }
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x > n) x++;
    if (y > n) y++;
    if (x % (n + 1) > y % (n + 1) ||
        (x % (n + 1) == y % (n + 1) &&
         F[x % (n + 1)][x / (n + 1)] > F[y % (n + 1)][y / (n + 1)]))
      swap(x, y);
    if (V.quest(x) != V.quest(y)) {
      puts("-1");
      continue;
    }
    int ans = 0;
    int aa = erfen(x % (n + 1));
    if (aa == erfen(y % (n + 1))) {
      ans = abs(x % (n + 1) - y % (n + 1)) + abs(x / (n + 1) - y / (n + 1));
    } else if (F[x % (n + 1)][x / (n + 1)] <= F[x % (n + 1)][1 - x / (n + 1)] ||
               S[aa] / (n + 1) != x / (n + 1)) {
      ans = F[y % (n + 1)][y / (n + 1)] - F[x % (n + 1)][x / (n + 1)];
    } else {
      ans = F[y % (n + 1)][y / (n + 1)] - F[x % (n + 1)][1 - x / (n + 1)] + 1;
    }
    printf("%d\n", ans);
  }
}
