#include <bits/stdc++.h>
using namespace std;
const int inf = 998244353;
int n, m;
char s[2][200005];
struct segtree {
  int l, r, dp[2][2];
} tr[1000005];
segtree merge(segtree a, segtree b) {
  segtree c;
  c.l = a.l, c.r = b.r;
  c.dp[0][0] = min(inf, min(a.dp[0][0] + b.dp[0][0], a.dp[0][1] + b.dp[1][0]));
  c.dp[0][1] = min(inf, min(a.dp[0][0] + b.dp[0][1], a.dp[0][1] + b.dp[1][1]));
  c.dp[1][0] = min(inf, min(a.dp[1][0] + b.dp[0][0], a.dp[1][1] + b.dp[1][0]));
  c.dp[1][1] = min(inf, min(a.dp[1][0] + b.dp[0][1], a.dp[1][1] + b.dp[1][1]));
  return c;
}
void build(int ind, int l, int r) {
  tr[ind].l = l, tr[ind].r = r;
  if (l == r) {
    if (s[0][l] == '.' && s[1][l] == '.') {
      tr[ind].dp[0][0] = tr[ind].dp[1][1] = 1;
      tr[ind].dp[1][0] = tr[ind].dp[0][1] = 2;
    } else if (s[0][l] == '.') {
      tr[ind].dp[0][0] = 1;
      tr[ind].dp[0][1] = tr[ind].dp[1][0] = tr[ind].dp[1][1] = inf;
    } else if (s[1][l] == '.') {
      tr[ind].dp[1][1] = 1;
      tr[ind].dp[0][1] = tr[ind].dp[1][0] = tr[ind].dp[0][0] = inf;
    } else {
      tr[ind].dp[0][1] = tr[ind].dp[1][0] = tr[ind].dp[0][0] =
          tr[ind].dp[1][1] = inf;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(ind << 1, l, mid);
  build(ind << 1 | 1, mid + 1, r);
  tr[ind] = merge(tr[ind << 1], tr[ind << 1 | 1]);
}
segtree query(int ind, int x, int y) {
  int l = tr[ind].l, r = tr[ind].r;
  if (x <= l && r <= y) {
    return tr[ind];
  }
  int mid = (l + r) >> 1;
  if (mid >= y)
    return query(ind << 1, x, y);
  else if (mid < x)
    return query(ind << 1 | 1, x, y);
  else
    return merge(query(ind << 1, x, y), query(ind << 1 | 1, x, y));
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%s %s", s[0] + 1, s[1] + 1);
  build(1, 1, n);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d %d", &u, &v);
    int tagu = 0, tagv = 0;
    if (u > n) u -= n, tagu = 1;
    if (v > n) v -= n, tagv = 1;
    if (u > v) {
      swap(u, v);
      swap(tagu, tagv);
    }
    segtree ans = query(1, u, v);
    printf("%d\n", ans.dp[tagu][tagv] == inf ? -1 : ans.dp[tagu][tagv] - 1);
  }
  return 0;
}
