#include <bits/stdc++.h>
const int inf = 707406378;
struct matrix {
  int a[3][3];
};
struct SegmentTree {
  int l, r;
  matrix dat;
} t[800001];
int n, m, q;
int a[3][200001];
char ch[200000];
matrix operator*(const matrix &a, const matrix &b) {
  matrix c;
  memset(c.a, 127 / 3, sizeof(c.a));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++)
        c.a[i][j] = std::min(c.a[i][j], a.a[i][k] + b.a[k][j] + 1);
  return c;
}
void init(SegmentTree &tmp, int pos) {
  memset(tmp.dat.a, 127 / 3, sizeof(tmp.dat.a));
  for (int i = 1; i <= n; i++) {
    if (a[i][pos]) tmp.dat.a[i][i] = 0;
    for (int j = i - 1; j >= 1; j--)
      if (a[j][pos] && tmp.dat.a[i][j + 1] < inf)
        tmp.dat.a[i][j] = tmp.dat.a[i][j + 1] + 1;
      else
        break;
    for (int j = i + 1; j <= n; j++)
      if (a[j][pos] && tmp.dat.a[i][j - 1] < inf)
        tmp.dat.a[i][j] = tmp.dat.a[i][j - 1] + 1;
      else
        break;
  }
}
void build(int p, int l, int r) {
  t[p].l = l;
  t[p].r = r;
  if (l == r) {
    init(t[p], l);
    return;
  }
  int mid = l + r >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  t[p].dat = t[p << 1].dat * t[p << 1 | 1].dat;
}
matrix query(int p, int l, int r) {
  if (l <= t[p].l && t[p].r <= r) return t[p].dat;
  int mid = t[p].l + t[p].r >> 1;
  if (l <= mid && r > mid)
    return query(p << 1, l, r) * query(p << 1 | 1, l, r);
  else if (l <= mid)
    return query(p << 1, l, r);
  else
    return query(p << 1 | 1, l, r);
}
int main() {
  scanf("%d %d", &m, &q);
  n = 2;
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch);
    for (int j = 1; j <= m; j++)
      if (ch[j - 1] == '.') a[i][j] = 1;
  }
  build(1, 1, m);
  for (int x, y; q; q--) {
    scanf("%d %d", &x, &y);
    int x1, y1, x2, y2;
    if (x > m)
      x1 = 2, y1 = x - m;
    else
      x1 = 1, y1 = x;
    if (y > m)
      x2 = 2, y2 = y - m;
    else
      x2 = 1, y2 = y;
    if (y1 > y2) std::swap(y1, y2), std::swap(x1, x2);
    matrix res = query(1, y1, y2);
    if (res.a[x1][x2] == inf)
      printf("-1\n");
    else
      printf("%d\n", res.a[x1][x2]);
  }
}
