#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 200000 + 10, L = 25;
int n = 1, m, q, par[2 * N][L + 1], p[2 * N], h[2 * N], a[2][N];
vector<int> adj[2 * N];
set<pair<int, int> > st;
string mp[2];
bool mark[2 * N];
inline void input() { cin >> m >> q >> mp[0] >> mp[1]; }
void DFS(int u) {
  mark[u] = true;
  for (int i = 0; i < adj[u].size(); i++)
    if (!mark[adj[u][i]]) {
      mark[adj[u][i]] = true;
      h[adj[u][i]] = h[u] + 1;
      par[adj[u][i]][0] = u;
      DFS(adj[u][i]);
    }
}
int findRoot(int u) {
  if (p[u] == u) return u;
  return p[u] = findRoot(p[u]);
}
int LCA(int x, int y) {
  if (h[x] > h[y]) swap(x, y);
  for (int i = L; i >= 0; i--)
    if (h[par[y][i]] >= h[x]) y = par[y][i];
  if (x == y) return x;
  for (int i = L; i >= 0; i--)
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  return par[x][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  input();
  bool flag = false;
  for (int i = 0; i < m; i++) {
    if (flag && mp[0][i] == 'X') {
      n++;
      flag = false;
      continue;
    }
    a[0][i] = n;
    flag = true;
  }
  if (mp[0][m - 1] == '.') n++;
  for (int i = 0; i < m; i++) {
    if (flag && mp[1][i] == 'X') {
      n++;
      flag = false;
      continue;
    }
    a[1][i] = n;
    flag = true;
  }
  if (mp[1][m - 1] == 'X') n--;
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 0; i < m; i++)
    if (mp[0][i] == '.' && mp[1][i] == '.')
      if (st.find(make_pair(a[0][i], a[1][i])) == st.end()) {
        st.insert(make_pair(a[0][i], a[1][i]));
        adj[a[0][i]].push_back(a[1][i]);
        adj[a[1][i]].push_back(a[0][i]);
        int r1 = findRoot(a[0][i]);
        int r2 = findRoot(a[1][i]);
        if (r1 != r2) p[r1] = r2;
      }
  h[0] = -1;
  for (int i = 1; i <= n; i++)
    if (!mark[i]) DFS(i);
  for (int j = 1; j <= L; j++)
    for (int i = 1; i <= n; i++) par[i][j] = par[par[i][j - 1]][j - 1];
  while (q) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    int u = a[x / m][x % m];
    int v = a[y / m][y % m];
    int ru = findRoot(u);
    int rv = findRoot(v);
    if (ru != rv)
      cout << -1 << endl;
    else
      cout << abs((x % m) - (y % m)) + h[u] + h[v] - 2 * h[LCA(u, v)] << endl;
    q--;
  }
  return 0;
}
