#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int comp[2][200100];
int cur;
int n;
char a[2][200100];
int d[2][200100];
int p[2][400100];
pair<int, int> min1[400100];
void dfs(int x, int y) {
  if (a[x][y] == 'X') return;
  if ((x < 0) || (x > 1) || (y < 0) || (y >= n)) return;
  if (comp[x][y] != -1) return;
  min1[cur] = ((min1[cur] < make_pair(y, x)) ? (min1[cur]) : (make_pair(y, x)));
  comp[x][y] = cur;
  for (int k = (0); k < (4); ++k) dfs(x + dx[k], y + dy[k]);
}
void bfs(int x, int y) {
  d[x][y] = 0;
  p[0][0] = x;
  p[1][0] = y;
  int l = 0, r = 0;
  while (l <= r) {
    int cx = p[0][l];
    int cy = p[1][l];
    l++;
    for (int k = (0); k < (4); ++k) {
      int nx = cx + dx[k];
      int ny = cy + dy[k];
      if ((nx < 0) || (nx > 1) || (ny < 0) || (ny >= n) || (a[nx][ny] == 'X') ||
          (d[nx][ny] < 1000000000))
        continue;
      d[nx][ny] = d[cx][cy] + 1;
      r++;
      p[0][r] = nx;
      p[1][r] = ny;
    }
  }
}
int dp[2][200100];
int main() {
  int q;
  scanf("%d%d", &n, &q);
  for (int i = (0); i < (2); ++i) scanf("%s", a[i]);
  for (int i = (0); i < (2); ++i)
    for (int j = (0); j < (n); ++j) {
      comp[i][j] = -1;
      d[i][j] = 1000000000;
    }
  for (int i = (0); i < (2); ++i)
    for (int j = (0); j < (n); ++j) {
      if ((a[i][j] != 'X') && (comp[i][j] == -1)) {
        min1[cur] = make_pair(1000000000, 1000000000);
        dfs(i, j);
        cur++;
      }
    }
  for (int i = (0); i < (cur); ++i) {
    bfs(min1[i].second, min1[i].first);
  }
  for (int i = (0); i < (2); ++i) {
    for (int j = n - 1; j >= 0; --j) {
      if (a[i][j] == 'X') continue;
      if (j == n - 1)
        dp[i][j] = n;
      else if (a[i][j + 1] == 'X')
        dp[i][j] = j + 1;
      else
        dp[i][j] = dp[i][j + 1];
    }
  }
  for (int i = (0); i < (q); ++i) {
    int v1, v2;
    scanf("%d%d", &v1, &v2);
    v1--;
    v2--;
    int x1 = v1 / n;
    int y1 = v1 % n;
    int x2 = v2 / n;
    int y2 = v2 % n;
    if (comp[x1][y1] != comp[x2][y2])
      printf("-1\n");
    else {
      if (y2 < y1) {
        swap(x1, x2);
        swap(y1, y2);
      }
      if (y1 == y2) {
        if (x1 == x2)
          printf("0\n");
        else
          printf("1\n");
      } else {
        int res = 0;
        int v = dp[x1][y1];
        if (v > y2)
          res = ((x2 - x1 > 0) ? x2 - x1 : -(x2 - x1)) +
                ((y2 - y1 > 0) ? y2 - y1 : -(y2 - y1));
        else {
          int x3 = x1 ^ 1;
          int y3 = v;
          res = ((x3 - x1 > 0) ? x3 - x1 : -(x3 - x1)) +
                ((y3 - y1 > 0) ? y3 - y1 : -(y3 - y1));
          res += (d[x2][y2] - d[x3][y3]);
        }
        printf("%d\n", res);
      }
    }
  }
  return 0;
}
