#include <bits/stdc++.h>
using namespace std;
int f[400005][20];
int a[2][4000005], n;
void swap(pair<int, int> &a, pair<int, int> &b) {
  pair<int, int> t = a;
  a = b;
  b = t;
}
int find(pair<int, int> s, pair<int, int> t) {
  int x = s.first * n + s.second;
  int ans = 0;
  for (int i = 19; i >= 0; --i) {
    if (f[x][i] == 0) continue;
    int p1 = (f[x][i] - 1) / n, p2 = (f[x][i] - 1) % n + 1;
    if (p2 >= t.second) continue;
    ans += 1 << i;
    x = f[x][i];
  }
  if ((x - 1) % n + 1 != t.second)
    if (f[x][0]) x = f[x][0], ++ans;
  if ((x - 1) % n + 1 != t.second) return 100 * n;
  return ans + ((x - 1) / n != t.first);
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < 2; ++i)
    for (int j = 1; j <= n; ++j) {
      int ch;
      while (ch = getchar(), ch != '.' && ch != 'X')
        ;
      a[i][j] = ch == 'X';
    }
  for (int I = 0; I < 2; ++I)
    for (int i = 1; i <= n; ++i) {
      if (a[I][i]) continue;
      if (i < n && a[I][i + 1] == 0)
        f[I * n + i][0] = I * n + i + 1;
      else if (a[I ^ 1][i] == 0)
        f[I * n + i][0] = (I ^ 1) * n + i;
    }
  for (int j = 1; j < 20; ++j)
    for (int i = 1; i <= 2 * n; ++i) f[i][j] = f[f[i][j - 1]][j - 1];
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    pair<int, int> p, q;
    p = make_pair((x - 1) / n, (x - 1) % n + 1);
    q = make_pair((y - 1) / n, (y - 1) % n + 1);
    if (p.second > q.second) swap(p, q);
    int k = find(p, q);
    if (k > 10 * n)
      puts("-1");
    else
      printf("%d\n", k);
  }
  return 0;
}
