#include <bits/stdc++.h>
using namespace std;
char mat[4][200111];
int way[4][200111];
int n, m;
int con;
int xx[] = {0, -1, 0, 1};
int yy[] = {1, 0, -1, 0};
int kx[1000111];
int ky[1000111];
pair<int, int> dari[4][200111];
int dx, dy;
queue<pair<int, int> > q;
inline void dfs(int x, int y) {
  way[x][y] = 0;
  mat[x][y] = '*';
  dari[x][y] = pair<int, int>(dx, dy);
  q.push(pair<int, int>(x, y));
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    for (int i = 0; i <= 3; i++)
      if (mat[x + xx[i]][y + yy[i]] == '.') {
        way[x + xx[i]][y + yy[i]] = way[x][y] + 1;
        mat[x + xx[i]][y + yy[i]] = '*';
        dari[x + xx[i]][y + yy[i]] = pair<int, int>(dx, dy);
        q.push(pair<int, int>(x + xx[i], y + yy[i]));
      }
  }
}
int mem[4][200111];
inline int nex(int x, int y) {
  if (mat[x][y] == 'X') return y;
  if (y > n) return y;
  if (mem[x][y] != -1) return mem[x][y];
  return mem[x][y] = nex(x, y + 1);
}
inline int lain(int a) {
  if (a == 1) return 2;
  return 1;
}
inline int dist(int sx, int sy, int fx, int fy) {
  int to = nex(sx, sy);
  if (to >= fy) return abs(fx - sx) + abs(fy - sy);
  return abs(to - sy) + 1 + way[fx][fy] - way[lain(sx)][to];
}
int main() {
  memset(mat, 'X', sizeof(mat));
  memset(mem, -1, sizeof(mem));
  cin >> n >> m;
  for (int i = 0; i <= 3; i++)
    for (int j = 0; j <= n + 1; j++) way[i][j] = 1000111222;
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++) {
      scanf("\n%c", &mat[i][j]);
      kx[++con] = i;
      ky[con] = j;
    }
  for (int j = 1; j <= n; j++)
    for (int i = 1; i <= 2; i++)
      if (mat[i][j] == '.') {
        dx = i;
        dy = j;
        dfs(i, j);
      }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (mat[kx[a]][ky[a]] == 'X' or mat[kx[b]][ky[b]] == 'X') {
      puts("-1");
      continue;
    }
    if (dari[kx[a]][ky[a]] != dari[kx[b]][ky[b]]) {
      puts("-1");
      continue;
    }
    if (ky[a] == ky[b]) {
      if (kx[a] == kx[b])
        puts("0");
      else
        puts("1");
      continue;
    }
    if (ky[a] > ky[b]) swap(a, b);
    cout << dist(kx[a], ky[a], kx[b], ky[b]) << endl;
  }
}
