#include <bits/stdc++.h>
using namespace std;
int n, q;
char g[200005][2];
struct node {
  int l;
  int r;
  int d1;
  int d2;
  int d3;
  int d4;
  friend node operator+(node a, node b) {
    node ans;
    ans.l = a.l;
    ans.r = b.r;
    ans.d1 = min(0x3f3f3f3f, min(a.d1 + b.d1, a.d2 + b.d3) + 1);
    ans.d2 = min(0x3f3f3f3f, min(a.d1 + b.d2, a.d2 + b.d4) + 1);
    ans.d3 = min(0x3f3f3f3f, min(a.d3 + b.d1, a.d4 + b.d3) + 1);
    ans.d4 = min(0x3f3f3f3f, min(a.d4 + b.d4, a.d3 + b.d2) + 1);
    return ans;
  }
} tree[200005 << 2];
void push_up(int pos) { tree[pos] = tree[pos << 1] + tree[pos << 1 | 1]; }
void build(int l, int r, int pos) {
  tree[pos].l = l;
  tree[pos].r = r;
  if (l == r) {
    tree[pos].d1 = tree[pos].d2 = tree[pos].d3 = tree[pos].d4 = 0x3f3f3f3f;
    if (g[l][1] == '.') tree[pos].d1 = 0;
    if (g[l][2] == '.') tree[pos].d4 = 0;
    if (g[l][1] == '.' && g[l][2] == '.') tree[pos].d2 = tree[pos].d3 = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, pos << 1);
  build(mid + 1, r, pos << 1 | 1);
  push_up(pos);
}
node query(int L, int R, int pos) {
  if (L <= tree[pos].l && R >= tree[pos].r) {
    return tree[pos];
  }
  int mid = (tree[pos].l + tree[pos].r) >> 1;
  if (R <= mid)
    return query(L, R, pos << 1);
  else if (L > mid)
    return query(L, R, pos << 1 | 1);
  else
    return query(L, R, pos << 1) + query(L, R, pos << 1 | 1);
}
int get_dis(int x, int y) {
  int u = (x - 1) % n + 1;
  int v = (y - 1) % n + 1;
  if (u > v) {
    swap(u, v);
    swap(x, y);
  }
  node ans = query(u, v, 1);
  if (x <= n && y <= n) return ans.d1;
  if (x <= n && y > n) return ans.d2;
  if (x > n && y <= n) return ans.d3;
  if (x > n && y > n) return ans.d4;
}
char tmp[200005];
int main() {
  int u, v;
  scanf("%d %d", &n, &q);
  char c;
  for (int i = 1; i <= 2; i++) {
    scanf("%s", tmp);
    for (int j = 1; j <= n; j++) {
      g[j][i] = tmp[j - 1];
    }
  }
  build(1, n, 1);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &u, &v);
    int ans = get_dis(u, v);
    if (ans == 0x3f3f3f3f) ans = -1;
    printf("%d\n", ans);
  }
}
