#include <bits/stdc++.h>
using namespace std;
const int MX = 200010;
const int MX_L = 18;
char G[2][MX];
int dp[MX_L][200010][2][2], n;
void init() {
  for (int i = 0; i < 18; i++) {
    for (int j = 0; j < 200010; j++) {
      for (int a = 0; a < 2; a++)
        for (int b = 0; b < 2; b++) dp[i][j][a][b] = 1e9;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    for (int a = 0; a < 2; a++) {
      for (int b = 0; b < 2; b++) {
        if (G[a][i] == 'X' || G[b][i + 1] == 'X') continue;
        if (a == b)
          dp[0][i][a][b] = 1;
        else {
          if (G[a][i + 1] == 'X' && G[b][i] == 'X') continue;
          dp[0][i][a][b] = 2;
        }
      }
    }
  }
  for (int i = 0; i < MX_L - 1; i++)
    for (int j = 0; j < n; j++)
      if ((1 << i) + j < n) {
        for (int a = 0; a < 2; a++)
          for (int b = 0; b < 2; b++)
            for (int c = 0; c < 2; c++) {
              dp[i + 1][j][a][c] =
                  min(dp[i + 1][j][a][c],
                      dp[i][j][a][b] + dp[i][j + (1 << i)][b][c]);
            }
      }
}
int solve(int a, int b) {
  int ay = a / n, by = b / n;
  int ax = a % n, bx = b % n;
  if (ax > bx) swap(ax, bx), swap(ay, by);
  if (a == b) {
    return 0;
  } else if (ax == bx) {
    if (G[ay][ax] == 'X' || G[by][bx] == 'X') return -1;
    return 1;
  }
  int dist = bx - ax;
  int ans[2], pdp[2];
  ans[0] = ans[1] = 1e9;
  ans[ay] = 0;
  for (int bit = 0; bit < 18; bit++) {
    if (dist & (1 << bit)) {
      pdp[0] = ans[0], pdp[1] = ans[1];
      ans[0] = ans[1] = 1e9;
      for (int a = 0; a < 2; a++)
        for (int b = 0; b < 2; b++) {
          ans[b] = min(ans[b], pdp[a] + dp[bit][ax][a][b]);
        }
      ax += (1 << bit);
    }
  }
  return (ans[by] == 1e9) ? -1 : ans[by];
}
int main() {
  int m;
  cin >> n >> m;
  for (int i = 0; i < 2; i++) scanf("%s", G[i]);
  init();
  int a, b;
  while (m--) {
    scanf("%d %d", &a, &b);
    printf("%d\n", solve(a - 1, b - 1));
  }
  return 0;
}
