#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:5000000000")
int size;
using namespace std;
template <class telem>
telem GCD(telem a, telem b) {
  return b ? GCD(b, a % b) : a;
}
template <class telem>
telem LCM(telem a, telem b) {
  return a / GCD(a, b) * b;
}
template <class telem>
istream& operator>>(istream& cin, pair<telem, telem>& in) {
  cin >> in.first >> in.second;
  return cin;
}
template <class telem>
ostream& operator<<(ostream& cout, pair<telem, telem> out) {
  cout << out.first << ' ' << out.second;
  return cout;
}
template <class telem>
istream& operator>>(istream& cin, vector<telem>& in) {
  in.resize(size);
  for (int i = 0; i < size; i++) {
    cin >> in[i];
  }
  return cin;
}
template <class telem>
ostream& operator<<(ostream& cout, vector<telem> out) {
  size = out.size();
  for (int i = 0; i < size; i++) {
    cout << out[i] << ' ';
  }
  return cout;
}
template <class telem>
istream& operator>>(istream& cin, telem* in) {
  for (int i = 0; i < size; i++) {
    cin >> in[i];
  }
  return cin;
}
int n, m;
string maze[2];
vector<int> g[4200005];
int cnt[200005];
int l[200005];
int r[200005];
int sum[200005];
int cm[400005];
int cn;
void dfs(int v) {
  cm[v] = cn;
  for (int i = 0; i < (int)g[v].size(); i++) {
    if (cm[g[v][i]] == 0) dfs(g[v][i]);
  }
}
bool diff(int v1, int v2) {
  if (v1 <= n && v2 <= n) return false;
  if (v1 > n && v2 > n) return false;
  return true;
}
int get_type(int i) {
  if (maze[0][i] == maze[1][i]) {
    if (maze[0][i] == '#') return 0;
    return 3;
  }
  if (maze[0][i] == '.') return 1;
  return 2;
}
int get_type_pos(int v) {
  if (v <= n) return 1;
  return 2;
}
int get_pos(int v) {
  if (v > n) v -= n;
  return v;
}
int get_dist(int v1, int v2) {
  v1 = get_pos(v1);
  v2 = get_pos(v2);
  if (v1 > v2) swap(v1, v2);
  return v2 - v1;
}
int main() {
  srand(time(NULL));
  time_t start = clock();
  cin >> n >> m >> maze[0] >> maze[1];
  for (int i = 0; i < n; i++) {
    if ((maze[0][i] == 'X' && maze[1][i] != 'X') ||
        (maze[0][i] != 'X' && maze[1][i] == 'X'))
      cnt[i + 1] = 1;
    if (maze[0][i] == '.') {
      if (i && maze[0][i - 1] == '.') {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
      }
      if (maze[1][i] == '.') {
        g[i + 1].push_back(i + n + 1);
        g[i + n + 1].push_back(i + 1);
      }
    }
    if (maze[1][i] == '.') {
      if (i && maze[1][i - 1] == '.') {
        g[i + n].push_back(i + n + 1);
        g[i + n + 1].push_back(i + n);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (cm[i] == 0) {
      cn++;
      dfs(i);
    }
  }
  int lst = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[i]) lst = i;
    l[i] = lst;
  }
  lst = n;
  for (int i = n; i > 0; i--) {
    if (cnt[i]) lst = i;
    r[i] = lst;
  }
  lst = 0;
  for (int i = 0, tmp; i < n; i++) {
    sum[i + 1] = sum[i];
    cnt[i + 1] += cnt[i];
    tmp = get_type(i);
    if (lst && tmp && tmp < 3 && tmp != lst) sum[i + 1]++;
    if (tmp < 3) lst = tmp;
  }
  int a, b;
  while (m-- > 0) {
    scanf("%d %d", &a, &b);
    if (cm[a] != cm[b]) {
      puts("-1");
      continue;
    }
    int pa = get_pos(a);
    int push_back = get_pos(b);
    if (pa > push_back) {
      swap(a, b);
      swap(pa, push_back);
    }
    if (cnt[push_back] - cnt[pa] == 0) {
      printf("%d\n", get_dist(pa, push_back) + diff(a, b));
      continue;
    }
    int aa = r[pa];
    int bb = l[push_back];
    printf("%d\n", get_dist(pa, aa) + (get_type_pos(a) != get_type(aa - 1)) +
                       get_dist(bb, push_back) +
                       (get_type(bb - 1) != get_type_pos(b)) +
                       get_dist(aa, bb) + sum[bb] - sum[aa]);
  }
  return 0;
}
