#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 20;
int n, m;
bool maze[2][200011];
pair<int, int> s[200011];
pair<int, int> t[200011];
int dr[4] = {0, 1, 0, -1};
int dc[4] = {1, 0, -1, 0};
vector<int> dists[20][2][2];
void getdist_rec(int lv, int left, int right) {
  if (left > right) return;
  int mid = (left + right) / 2;
  for (int r0 = 0; r0 < 2; r0++) {
    vector<int>* dist = dists[lv][r0];
    for (int r = 0; r < 2; r++)
      for (int c = left; c <= right; c++) dist[r][c] = INF;
    if (!maze[r0][mid]) continue;
    vector<pair<int, int> > q, nq;
    dist[r0][mid] = 0;
    nq.push_back(pair<int, int>(r0, mid));
    int dd = 0;
    while (!nq.empty()) {
      q.swap(nq);
      while (!q.empty()) {
        int r = q.back().first;
        int c = q.back().second;
        q.pop_back();
        for (int k = 0; k < 4; k++) {
          int rr = r + dr[k];
          int cc = c + dc[k];
          if (rr < 0 || cc < left || rr >= 2 || cc > right) continue;
          if (!maze[rr][cc]) continue;
          if (dist[rr][cc] == INF) {
            dist[rr][cc] = dd + 1;
            nq.push_back(pair<int, int>(rr, cc));
          }
        }
      }
      dd++;
    }
  }
  getdist_rec(lv + 1, left, mid - 1);
  getdist_rec(lv + 1, mid + 1, right);
}
int getLevels(int left, int right) {
  if (left > right) return 0;
  int mid = (left + right) / 2;
  return max(getLevels(left, mid - 1), getLevels(mid + 1, right)) + 1;
}
int query_rec(int lv, int left, int right, int sr, int sc, int tr, int tc) {
  int mid = (left + right) / 2;
  if ((sc <= mid && tc >= mid) || (tc <= mid && sc >= mid)) {
    int res = INF;
    for (int r0 = 0; r0 < 2; r0++) {
      int next = dists[lv][r0][sr][sc] + dists[lv][r0][tr][tc];
      res = min(res, next);
    }
    return res;
  } else if (sc < mid && tc < mid) {
    return query_rec(lv + 1, left, mid - 1, sr, sc, tr, tc);
  } else if (sc > mid && tc > mid) {
    return query_rec(lv + 1, mid + 1, right, sr, sc, tr, tc);
  } else {
    cerr << "Error!!" << endl;
    return INF;
  }
}
void solve() {
  int level = getLevels(0, n - 1);
  for (int lv = 0; lv < level; lv++)
    for (int r0 = 0; r0 < 2; r0++)
      for (int r1 = 0; r1 < 2; r1++) dists[lv][r0][r1].assign(n, INF);
  getdist_rec(0, 0, n - 1);
  for (int i = 0; i < m; i++) {
    int ans = query_rec(0, 0, n - 1, s[i].first, s[i].second, t[i].first,
                        t[i].second);
    if (ans >= INF) ans = -1;
    cout << ans << endl;
  }
}
void coding() {
  while (cin >> n >> m) {
    string line;
    for (int i = 0; i < 2; i++) {
      cin >> line;
      for (int j = 0; j < n; j++) {
        maze[i][j] = (line[j] == '.');
      }
    }
    for (int i = 0; i < m; i++) {
      int p, q;
      cin >> p >> q;
      p--;
      q--;
      s[i].first = p / n;
      s[i].second = p % n;
      t[i].first = q / n;
      t[i].second = q % n;
    }
    solve();
  }
}
int main() { coding(); }
