#include <bits/stdc++.h>
using namespace std;
struct node {
  int dd, du, ud, uu;
  void mix(node ls, node rs) {
    uu = min(0x3f3f3f3f, min(ls.uu + rs.uu, ls.ud + rs.du) + 1);
    dd = min(0x3f3f3f3f, min(ls.dd + rs.dd, ls.du + rs.ud) + 1);
    ud = min(0x3f3f3f3f, min(ls.uu + rs.ud, ls.ud + rs.dd) + 1);
    du = min(0x3f3f3f3f, min(ls.dd + rs.du, ls.du + rs.uu) + 1);
  }
} t[200005 * 4];
int n, m, ql, qr;
char mp[2][200005];
void build(int p, int l, int r) {
  if (l == r) {
    if (mp[0][l] == '.')
      t[p].uu = 0;
    else
      t[p].uu = 0x3f3f3f3f;
    if (mp[1][l] == '.')
      t[p].dd = 0;
    else
      t[p].dd = 0x3f3f3f3f;
    if (mp[0][l] == '.' && mp[1][l] == '.')
      t[p].du = t[p].ud = 1;
    else
      t[p].du = t[p].ud = 0x3f3f3f3f;
    return;
  }
  int mid = l + r >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  t[p].mix(t[p << 1], t[p << 1 | 1]);
}
node query(int p, int l, int r) {
  if (ql <= l && r <= qr) return t[p];
  int mid = l + r >> 1;
  if (qr <= mid) return query(p << 1, l, mid);
  if (ql > mid) return query(p << 1 | 1, mid + 1, r);
  node a = query(p << 1, l, mid), b = query(p << 1 | 1, mid + 1, r);
  a.mix(a, b);
  return a;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s%s", mp[0] + 1, mp[1] + 1);
  build(1, 1, n);
  int way, ans;
  while (m--) {
    way = 0;
    scanf("%d%d", &ql, &qr);
    if (ql > n) ql -= n, way += 2;
    if (qr > n) qr -= n, ++way;
    if (ql > qr) swap(ql, qr), way = (way >> 1) + ((way << 1) & 2);
    node x = query(1, 1, n);
    if (way == 0)
      ans = x.uu;
    else if (way == 1)
      ans = x.ud;
    else if (way == 2)
      ans = x.du;
    else if (way == 3)
      ans = x.dd;
    if (ans == 0x3f3f3f3f)
      puts("-1");
    else
      printf("%d\n", ans);
  }
  return 0;
}
