#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int res = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
  return res;
}
namespace BriMon {
int n, q;
char mp[3][200005];
struct date {
  int d1, d2, d3, d4;
} tr[200005 << 2];
inline date Merge(date a, date b) {
  date res;
  res.d1 = min(0x3f3f3f3f, min(a.d1 + b.d1, a.d2 + b.d3) + 1);
  res.d2 = min(0x3f3f3f3f, min(a.d2 + b.d4, a.d1 + b.d2) + 1);
  res.d3 = min(0x3f3f3f3f, min(a.d3 + b.d1, a.d4 + b.d3) + 1);
  res.d4 = min(0x3f3f3f3f, min(a.d4 + b.d4, a.d3 + b.d2) + 1);
  return res;
}
void build(int l, int r, int o) {
  if (l == r) {
    tr[o] = (date){0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f};
    if (mp[1][l] == '.') tr[o].d1 = 0;
    if (mp[2][l] == '.') tr[o].d4 = 0;
    if (mp[1][l] == '.' and mp[2][l] == '.') tr[o].d3 = tr[o].d2 = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, o << 1), build(mid + 1, r, o << 1 | 1);
  tr[o] = Merge(tr[o << 1], tr[o << 1 | 1]);
}
date query(int l, int r, int o, int ql, int qr) {
  if (l == ql and r == qr) return tr[o];
  int mid = (l + r) >> 1;
  if (qr <= mid) return query(l, mid, o << 1, ql, qr);
  if (ql > mid) return query(mid + 1, r, o << 1 | 1, ql, qr);
  return Merge(query(l, mid, o << 1, ql, mid),
               query(mid + 1, r, o << 1 | 1, mid + 1, qr));
}
int solve(int x, int y) {
  int a = (x - 1) % n + 1, b = (y - 1) % n + 1;
  if (a > b) swap(a, b), swap(x, y);
  date tmp = query(1, n, 1, a, b);
  if (x <= n and y <= n) return tmp.d1;
  if (x <= n and y > n) return tmp.d2;
  if (x > n and y <= n) return tmp.d3;
  if (x > n and y > n) return tmp.d4;
}
signed main() {
  n = read(), q = read();
  scanf("%s%s", mp[1] + 1, mp[2] + 1);
  build(1, n, 1);
  for (register int i = 1; i <= q; i++) {
    int ans = solve(read(), read());
    if (ans == 0x3f3f3f3f)
      puts("-1");
    else
      printf("%d\n", ans);
  }
  return 0;
}
}  // namespace BriMon
int main() {
  BriMon ::main();
  return 0;
}
