#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, INF = 1e9;
vector<bool> u(N), d(N);
int n, m;
namespace IO {
const int MAXSIZE = 1 << 20;
char buf[MAXSIZE], *p1, *p2;
inline char getc() {
  return (p1 == p2 &&
                  (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)
              ? EOF
              : *p1++);
}
inline int read(int &x) {
  x = 0;
  int c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (!isdigit(c))
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)
             ? EOF
             : *p1++);
  while (isdigit(c))
    x = x * 10 + (c ^ 48),
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)
             ? EOF
             : *p1++);
  return x;
}
char pbuf[1 << 20], *pp = pbuf;
inline void push(const char &c) {
  if (pp - pbuf == 1 << 20) fwrite(pbuf, 1, 1 << 20, stdout), pp = pbuf;
  *pp++ = c;
}
inline void write(int x) {
  if (x == INF) {
    push('-'), push('1'), push('\n');
    return;
  }
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) push(sta[--top] + '0');
  push('\n');
}
void flush() { fwrite(pbuf, 1, pp - pbuf, stdout); }
}  // namespace IO
using IO::flush;
using IO::getc;
using IO::read;
using IO::write;
struct msg {
  int uu, ud, du, dd;
  msg operator+(msg b) {
    msg ans;
    ans.uu = min(INF, min(uu + b.uu, ud + b.du) + 1);
    ans.ud = min(INF, min(uu + b.ud, ud + b.dd) + 1);
    ans.du = min(INF, min(dd + b.du, du + b.uu) + 1);
    ans.dd = min(INF, min(dd + b.dd, du + b.ud) + 1);
    return ans;
  }
} val[N], inf = (msg){INF, INF, INF, INF}, ans;
void build(int rt = 1, int l = 1, int r = n) {
  if (l == r) {
    val[rt] = inf;
    if (u[l]) val[rt].uu = 0;
    if (d[l]) val[rt].dd = 0;
    if (u[l] && d[l]) val[rt].ud = val[rt].du = 1;
    return;
  }
  int mid = l + r >> 1;
  build((rt << 1), l, mid);
  build(((rt << 1) | 1), mid + 1, r);
  val[rt] = val[(rt << 1)] + val[((rt << 1) | 1)];
}
msg query(int L, int R, int rt = 1, int l = 1, int r = n) {
  if (L <= l && R >= r) return val[rt];
  int mid = l + r >> 1;
  if (R <= mid) return query(L, R, (rt << 1), l, mid);
  if (L > mid) return query(L, R, ((rt << 1) | 1), mid + 1, r);
  return query(L, R, (rt << 1), l, mid) +
         query(L, R, ((rt << 1) | 1), mid + 1, r);
}
int main() {
  read(n), read(m);
  char c = getc();
  while (c != '.' && c != 'X') c = getc();
  for (int i = 1; i <= n; ++i) u[i] = c == '.', c = getc();
  while (c != '.' && c != 'X') c = getc();
  for (int i = 1; i <= n; ++i) d[i] = c == '.', c = getc();
  build();
  while (m--) {
    int u, v;
    read(u), read(v);
    int u_ = (u - 1) % n + 1, v_ = (v - 1) % n + 1;
    if (u_ > v_) swap(u_, v_), swap(u, v);
    ans = query(u_, v_);
    if (u <= n)
      if (v <= n)
        write(ans.uu);
      else
        write(ans.ud);
    else if (v <= n)
      write(ans.du);
    else
      write(ans.dd);
  }
  flush();
}
