#include <bits/stdc++.h>
using namespace std;
char s[2][200010];
int pd[2][200010][2][20];
int mymin(int a, int b) { return min(min(a, b), 0x3f3f3f3f); }
int main() {
  int n, q;
  scanf(" %d %d", &n, &q);
  for (int i = 0; i < 2; i++) scanf(" %s", s[i]);
  memset(pd, 0x3f, sizeof(pd));
  for (int j = 0; j < n - 1; j++) {
    for (int i = 0; i < 2; i++) {
      if (s[i][j] == '.') {
        if (s[i][j + 1] == '.') pd[i][j][i][0] = 1;
        if (s[i ^ 1][j + 1] == '.' &&
            (s[i][j + 1] == '.' || s[i ^ 1][j] == '.'))
          pd[i][j][i ^ 1][0] = 2;
      }
    }
  }
  for (int sz = 1; sz < 20; sz++) {
    for (int i = 0; i < 2; i++)
      for (int j = 0; j + (1 << sz) < n; j++) {
        pd[i][j][i][sz] =
            mymin(pd[i][j][i][sz - 1] + pd[i][j + (1 << (sz - 1))][i][sz - 1],
                  pd[i][j][i ^ 1][sz - 1] +
                      pd[i ^ 1][j + (1 << (sz - 1))][i][sz - 1]);
        pd[i][j][i ^ 1][sz] = mymin(
            pd[i][j][i][sz - 1] + pd[i][j + (1 << (sz - 1))][i ^ 1][sz - 1],
            pd[i][j][i ^ 1][sz - 1] +
                pd[i ^ 1][j + (1 << (sz - 1))][i ^ 1][sz - 1]);
      }
  }
  int a, b;
  while (q--) {
    scanf(" %d %d", &a, &b);
    int la = (a - 1) / n;
    int ca = (a - 1) % n;
    int lb = (b - 1) / n;
    int cb = (b - 1) % n;
    if (ca > cb) {
      swap(la, lb);
      swap(ca, cb);
    }
    int ans[2];
    ans[0] = 0x3f3f3f3f;
    ans[1] = 0x3f3f3f3f;
    if (la == 0) {
      ans[0] = 0;
      if (s[1][ca] == '.') ans[1] = 1;
    } else {
      ans[1] = 0;
      if (s[0][ca] == '.') ans[0] = 1;
    }
    int c = ca;
    for (int i = 20 - 1; i >= 0; i--) {
      if (c + (1 << i) <= cb) {
        int aux0 = mymin(ans[0] + pd[0][c][0][i], ans[1] + pd[1][c][0][i]);
        int aux1 = mymin(ans[0] + pd[0][c][1][i], ans[1] + pd[1][c][1][i]);
        ans[0] = aux0;
        ans[1] = aux1;
        c += (1 << i);
      }
    }
    if (ans[lb] >= 0x3f3f3f3f)
      printf("-1\n");
    else
      printf("%d\n", ans[lb]);
  }
  return 0;
}
