#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5, lg = 19;
int depth[N], sp[N][lg], id = 1, dsu[N], sz[N];
int n, q;
string x[2];
vector<vector<int> > node;
void dfs(int v, int p) {
  depth[v] = 1 + depth[p];
  sp[v][0] = p;
  for (auto i : node[v])
    if (i != p) dfs(i, v);
}
void build() {
  for (auto j = 1; j < (long long)(lg); j++)
    for (auto i = 0; i < (long long)(2 * n); i++)
      sp[i][j] = sp[sp[i][j - 1]][j - 1];
}
int LCA(int u, int v) {
  if (depth[v] > depth[u]) swap(u, v);
  int diff = depth[u] - depth[v];
  for (int i = lg - 1; i >= 0; i--)
    if (diff & (1 << i)) u = sp[u][i];
  if (u == v) return u;
  for (int i = lg - 1; i >= 0; i--)
    if (sp[u][i] != sp[v][i]) u = sp[u][i], v = sp[v][i];
  return sp[u][0];
}
int root(int u) { return (u == dsu[u] ? u : dsu[u] = root(dsu[u])); }
void merge(int u, int v) { dsu[root(u)] = root(v); }
int dist(int a, int b) {
  int lca = LCA(a, b);
  return depth[a] + depth[b] - 2 * depth[lca];
}
int get(int a, int b) {
  if (root(a) != root(b)) return -1;
  int d1, d2;
  d1 = dist(a, b);
  if (b < n)
    d2 = dist(a, b + n);
  else
    d2 = dist(a, b - n);
  return min(d1, d2 + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  node.resize(2 * n + 1);
  for (auto i = 0; i < (long long)(2 * n); i++) dsu[i] = i, sz[i] = 1;
  cin >> x[0] >> x[1];
  for (auto i = 0; i < (long long)(n); i++) {
    if (x[0][i] == '.') {
      if (x[1][i] == '.' &&
          (i + 1 == n || (x[0][i + 1] == 'X' || x[1][i + 1] == 'X')))
        node[i].push_back(i + n), node[i + n].push_back(i), merge(i, i + n);
      if (i + 1 != n && x[0][i + 1] == '.')
        node[i].push_back(i + 1), node[i + 1].push_back(i), merge(i, i + 1);
    }
    if (x[1][i] == '.' && i + 1 != n && x[1][i + 1] == '.')
      node[i + n].push_back(i + n + 1), node[i + n + 1].push_back(i + n),
          merge(i + n, i + n + 1);
  }
  for (auto i = 0; i < (long long)(2 * n); i++)
    reverse(((node[i]).begin()), ((node[i]).end()));
  for (auto i = 0; i < (long long)(2 * n); i++)
    if (root(i) == i) dfs(i, i);
  build();
  while (q--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (a % n > b % n) swap(a, b);
    cout << get(a, b) << '\n';
  }
  return 0;
}
