#include <bits/stdc++.h>
using namespace std;
const int nmax = 200005;
struct item {
  int i;
  int j;
  int dist;
  item(int i, int j, int dist) : i(i), j(j), dist(dist){};
};
int main() {
  int n, m;
  cin >> n >> m;
  char c[2][nmax];
  for (int i = 0; i < 2; ++i) cin >> c[i];
  int dist[2][nmax] = {};
  bool used[2][nmax] = {};
  int mark[2][nmax] = {};
  int currentMark = 0;
  for (int j = 0; j < n; ++j)
    for (int i = 0; i < 2; ++i)
      if (!used[i][j] && c[i][j] == '.') {
        used[i][j] = 1;
        queue<item> q;
        q.push(item(i, j, 0));
        while (!q.empty()) {
          int x = q.front().i;
          int y = q.front().j;
          int d = q.front().dist;
          mark[x][y] = currentMark;
          dist[x][y] = d;
          q.pop();
          if (!used[1 - x][y] && c[1 - x][y] == '.') {
            q.push(item(1 - x, y, d + 1));
            used[1 - x][y] = 1;
          }
          if (!used[x][y + 1] && c[x][y + 1] == '.') {
            q.push(item(x, y + 1, d + 1));
            used[x][y + 1] = 1;
          }
        }
        ++currentMark;
      }
  int st[2][nmax] = {};
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < n; ++j)
      if (c[i][j] != '.') st[i][++st[i][0]] = j;
  for (int o = 0; o < m; ++o) {
    int x1, x2, y1, y2;
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    x1 = u / n;
    x2 = v / n;
    y1 = u % n;
    y2 = v % n;
    if (y1 > y2) {
      swap(x1, x2);
      swap(y1, y2);
    }
    if (mark[x1][y1] != mark[x2][y2])
      cout << -1 << '\n';
    else {
      int l = 1, r = st[x1][0];
      int res = nmax;
      while (l <= r) {
        int t = (l + r) / 2;
        if (st[x1][t] < y1)
          l = t + 1;
        else {
          res = min(res, st[x1][t]);
          r = t - 1;
        }
      }
      if (res - 1 >= y2)
        cout << y2 - y1 + abs(x2 - x1) << '\n';
      else
        cout << res - y1 + dist[x2][y2] - dist[1 - x1][res - 1] << '\n';
    }
  }
  return 0;
}
