#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct Bo {
  int l, r;
  int c[2][2];
  Bo() {}
  Bo(int l, int r, int len) : l(l), r(r) {
    if (l == 2) {
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
          c[i][j] = len + (i != j) - 1;
        }
      }
    } else {
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
          c[i][j] = len - 1;
        }
      }
    }
  }
  int *operator[](int x) { return c[x]; }
};
Bo operator+(Bo &a, Bo &b) {
  Bo e;
  e.l = a.l;
  e.r = b.r;
  if (a.r == 0 || b.l == 0) {
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        e[i][j] = a[i][0] + 1 + b[0][j];
      }
    }
  } else {
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        e[i][j] = a[i][1] + 1 + b[1][j];
      }
    }
  }
  return e;
}
struct Seg {
  Bo gao[N << 2];
  void Up(int rt) { gao[rt] = gao[rt << 1] + gao[rt << 1 | 1]; }
  void build(int rt, int l, int r, Bo A[]) {
    if (l == r) {
      gao[rt] = A[l];
      return;
    }
    int mid = r + l >> 1;
    build(rt << 1, l, mid, A);
    build(rt << 1 | 1, mid + 1, r, A);
    Up(rt);
  }
  Bo query(int rt, int l, int r, int L, int R) {
    if (l >= L && r <= R) {
      return gao[rt];
    }
    int mid = r + l >> 1;
    Bo ret;
    if (mid >= L) {
      ret = query(rt << 1, l, mid, L, R);
      if (R > mid) {
        Bo tmp = query(rt << 1 | 1, mid + 1, r, L, R);
        ret = ret + tmp;
      }
    } else {
      ret = query(rt << 1 | 1, mid + 1, r, L, R);
    }
    return ret;
  }
  void init(int n, Bo A[]) {
    build(1, 1, n, A);
    return;
  }
} AC;
int n, m;
char mp[3][N];
int A[N];
int ban[N];
int p[N];
int len[N];
int id[N];
pair<int, int> seg[N];
Bo g[N];
inline pair<int, int> change(int x) {
  return make_pair((x - 1) % n + 1, (x - 1) / n);
}
void work() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 2; i++) {
    scanf("%s", mp[i] + 1);
  }
  int tot = 0, flag = 1;
  for (int i = 1; i <= n; i++) {
    int a = -1;
    if (mp[1][i] == '.' && mp[2][i] == '.') {
      a = 2;
    } else if (mp[1][i] == '.') {
      a = 0;
    } else if (mp[2][i] == '.') {
      a = 1;
    }
    if (a == -1) {
      flag = 1;
      ban[i] = 1;
    } else {
      if (flag) {
        flag = 0;
        A[++tot] = a;
        p[tot] = tot;
        len[tot] = 1;
        seg[tot].first = seg[tot].second = i;
      } else {
        if (A[tot] == a) {
          len[tot]++;
          seg[tot].second++;
        } else {
          A[++tot] = a;
          if (A[tot] + A[tot - 1] == 1) {
            p[tot] = tot;
          } else {
            p[tot] = p[tot - 1];
          }
          len[tot] = 1;
          seg[tot].first = seg[tot].second = i;
        }
      }
      id[i] = tot;
    }
  }
  for (int i = 1; i <= tot; i++) {
    g[i] = Bo(A[i], A[i], len[i]);
  }
  AC.init(tot, g);
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    pair<int, int> u = change(a), v = change(b);
    if (u.first > v.first) swap(u, v);
    int x = id[u.first], y = id[v.first];
    if (ban[u.first] || ban[v.first] || p[x] != p[y]) {
      puts("-1");
    } else {
      Bo ret = AC.query(1, 1, tot, x, y);
      int ans = ret[u.second][v.second] - (u.first - seg[x].first) -
                (seg[y].second - v.first);
      printf("%d\n", ans);
    }
  }
  return;
}
int main() {
  work();
  return 0;
}
