#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
char A[2][200005];
int comp[2][200005];
int compCnt;
bool used[2][200005];
queue<int> q;
int n = 2;
int m;
int sum[200005];
vector<int> g;
int getSum(int l, int r) {
  if (l > r)
    return 0;
  else
    return sum[r] - (l - 1 >= 0 ? sum[l - 1] : 0);
}
void f(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m && !used[i][j] && A[i][j] != 'X') {
    used[i][j] = true;
    comp[i][j] = compCnt;
    q.push(i);
    q.push(j);
  }
}
int dist(int y1, int y2) { return abs(y1 - y2) + getSum(y1 + 1, y2); }
int getDot(int y) { return (A[0][y] == '.' ? 0 : 1); }
int findRight(int y) {
  int pos = lower_bound(g.begin(), g.end(), y) - g.begin();
  if (pos < g.size())
    return g[pos];
  else
    return 0x3f3f3f3f;
}
int findLeft(int y) {
  int pos = lower_bound(g.begin(), g.end(), y) - g.begin() - 1;
  if (pos >= 0)
    return g[pos];
  else
    return -0x3f3f3f3f;
}
int solve(int xLeft, int yLeft, int xRight, int yRight) {
  if (yLeft > yRight) swap(xLeft, xRight), swap(yLeft, yRight);
  if (binary_search(g.begin(), g.end(), yLeft) &&
      binary_search(g.begin(), g.end(), yRight))
    return dist(yLeft, yRight);
  else {
    int yLeftRight = findRight(yLeft);
    int yRightLeft = findLeft(yRight);
    if (yLeftRight > yRight || yRightLeft < yLeft)
      return abs(yLeft - yRight) + (xLeft != xRight);
    return (yLeftRight - yLeft + (xLeft != getDot(yLeftRight))) +
           (yRight - yRightLeft + (xRight != getDot(yRightLeft))) +
           solve(getDot(yLeftRight), yLeftRight, getDot(yRightLeft),
                 yRightLeft);
  }
}
int main() {
  int tst, i, j;
  cin >> m >> tst;
  for (i = 0; i < n; i++) scanf("%s", &A[i]);
  pair<char, char> lastType = make_pair('@', '@');
  for (j = 0; j < m; j++) {
    if (j - 1 >= 0) sum[j] = sum[j - 1];
    if ((A[0][j] == '.') + (A[1][j] == '.') == 1) {
      g.push_back(j);
      if (lastType != make_pair(A[0][j], A[1][j]))
        sum[j]++, lastType = make_pair(A[0][j], A[1][j]);
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (!used[i][j] && A[i][j] != 'X') {
        compCnt++;
        used[i][j] = true;
        comp[i][j] = compCnt;
        q.push(i);
        q.push(j);
        while (!q.empty()) {
          int x = q.front();
          q.pop();
          int y = q.front();
          q.pop();
          f(x - 1, y);
          f(x + 1, y);
          f(x, y - 1);
          f(x, y + 1);
        }
      }
    }
  }
  int a, b;
  while (tst--) {
    scanf("%d %d", &a, &b);
    a--, b--;
    int x1 = a / m, y1 = a % m;
    int x2 = b / m, y2 = b % m;
    if (comp[x1][y1] != comp[x2][y2])
      puts("-1");
    else
      printf("%d\n", solve(x1, y1, x2, y2));
  }
}
