#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 2e5 + 2;
int n, q, fLeft[2 * N], fRight[2 * N], cnt[N], cc[N << 1];
string s[2];
void dfs(int x, int c) {
  cc[x] = c;
  if (x <= n && !cc[x + n] && s[1][x] == '.') dfs(x + n, c);
  if (x > n && !cc[x - n] && s[0][x - n] == '.') dfs(x - n, c);
  if (x % n != 0 && !cc[x + 1] && s[x / n][x % n + 1] == '.') dfs(x + 1, c);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> q >> s[0] >> s[1];
  s[0] = '0' + s[0];
  s[1] = '0' + s[1];
  int lst = -1;
  for (int i = (1); i <= (n); ++i)
    if (s[0][i] != s[1][i]) {
      if (lst == -1)
        lst = (s[0][i] == '.');
      else if (lst != (s[0][i] == '.'))
        cnt[i] = 1, lst = (s[0][i] == '.');
    }
  for (int i = (2); i <= (n); ++i) cnt[i] += cnt[i - 1];
  lst = 0;
  for (int i = (1); i <= (n); ++i) {
    if (s[0][i] == 'X')
      lst = i;
    else
      fLeft[i] = lst;
  }
  lst = n + 1;
  for (int i = (n); i >= (1); --i) {
    if (s[0][i] == 'X')
      lst = i;
    else
      fRight[i] = lst;
  }
  lst = 0;
  for (int i = (1); i <= (n); ++i) {
    if (s[1][i] == 'X')
      lst = i;
    else
      fLeft[i + n] = lst;
  }
  lst = n + 1;
  for (int i = (n); i >= (1); --i) {
    if (s[1][i] == 'X')
      lst = i;
    else
      fRight[i + n] = lst;
  }
  for (int i = (1); i <= (n); ++i) {
    if (s[0][i] == '.' && !cc[i]) dfs(i, i);
    if (s[1][i] == '.' && !cc[i + n]) dfs(i + n, i);
  }
  while (q--) {
    int u, v;
    cin >> u >> v;
    if (cc[u] != cc[v])
      cout << "-1\n";
    else {
      if ((u - 1) % n > (v - 1) % n) swap(u, v);
      int pr = fRight[u], pl = fLeft[v];
      if (pr - 1 > (v - 1) % n || pl - 1 < (u - 1) % n)
        cout << ((v - 1) % n - (u - 1) % n +
                 ((u > n && v <= n) || (u <= n && v > n)))
             << '\n';
      else
        cout << ((v - 1) % n - (u - 1) % n + cnt[pl] - cnt[pr] + 2) << '\n';
    }
  }
  return 0;
}
