#include <bits/stdc++.h>
const int N = 200010;
using namespace std;
inline int rnd() {
  int res = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    res = res * 10 + ch - '0';
    ch = getchar();
  }
  return res * f;
}
inline void wr(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) wr(x / 10);
  putchar(x % 10 + '0');
}
int n, m, Q;
int w[10];
bool mp[3][N];
struct node {
  int a[3][3];
  node() { memset(a, -1, sizeof(a)); }
  inline int* operator[](const int x) { return a[x]; }
  node operator+(node b) const {
    node c;
    memset(c.a, 0x3f, sizeof(c.a));
    for (int k = 1; k <= n; k++)
      for (int i = 1; i <= n; i++)
        if (~a[i][k])
          for (int j = 1; j <= n; j++)
            if (~b[k][j]) c[i][j] = min(c[i][j], a[i][k] + b[k][j] + 1);
    return c;
  }
};
struct E {
  node t[N << 2];
  inline void init(int x, int k) {
    for (int i = 1, j; i <= n; i++) {
      for (j = i; j <= n && mp[j][x]; j++) t[k][i][j] = j - i;
      for (; j <= n; j++) t[k][i][j] = -1;
      for (j = i; j && mp[j][x]; j--) t[k][i][j] = i - j;
      for (; j; j--) t[k][i][j] = -1;
    }
  }
  inline void pushup(int k) { t[k] = t[k << 1] + t[k << 1 | 1]; }
  inline void build(int k, int l, int r) {
    if (l == r) {
      return init(l, k);
    }
    int mid = (l + r) >> 1;
    build(k << 1, l, mid);
    build(k << 1 | 1, mid + 1, r);
    pushup(k);
  }
  inline void change(int k, int l, int r, int x) {
    if (l == r) {
      return init(l, k);
    }
    int mid = (l + r) >> 1;
    if (x <= mid)
      change(k << 1, l, mid, x);
    else
      change(k << 1 | 1, mid + 1, r, x);
    pushup(k);
  }
  inline node ask(int k, int l, int r, int x, int y) {
    if (x <= l && y >= r) {
      return t[k];
    }
    int mid = (l + r) >> 1;
    if (y <= mid) return ask(k << 1, l, mid, x, y);
    if (x > mid) return ask(k << 1 | 1, mid + 1, r, x, y);
    return ask(k << 1, l, mid, x, y) + ask(k << 1 | 1, mid + 1, r, x, y);
  }
} T;
char ss[N];
int main() {
  cin >> m >> Q;
  n = 2;
  for (int i = 1; i <= n; i++) {
    scanf("%s", ss + 1);
    for (int j = 1; j <= m; j++) {
      if (ss[j] == '.')
        mp[i][j] = 1;
      else
        mp[i][j] = 0;
    }
  }
  T.build(1, 1, m);
  int x, y, tx, ty, xx, yy;
  node ans;
  for (int i = 1; i <= Q; i++) {
    xx = rnd();
    yy = rnd();
    if (xx <= m) {
      x = 1;
      y = xx;
    } else {
      x = 2, y = xx - m;
    }
    if (yy <= m) {
      tx = 1, ty = yy;
    } else {
      tx = 2, ty = yy - m;
    }
    if (y > ty) {
      swap(x, tx), swap(y, ty);
    }
    ans = T.ask(1, 1, m, y, ty);
    if (ans[x][tx] > 1e8)
      wr(-1);
    else
      wr(ans[x][tx]);
    puts("");
  }
  return 0;
}
