#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
const int oo = 1e9;
bool g[2][N];
char s[N];
int d[2][N], b[2][N], a[2][N], cl, n;
int l[2][N], r[2][N];
void dfs(int i, int j) {
  if ((a[i][j] == cl) || (!g[i][j])) return;
  a[i][j] = cl;
  dfs((i + 1) % 2, j);
  if (j < n) dfs(i, j + 1);
  if (j > 0) dfs(i, j - 1);
}
int main() {
  int i, j, m, u, i1, j1, i2, j2, ln, c1, c2, an;
  scanf("%d%d", &n, &m);
  for (i = 0; i < 2; ++i) {
    scanf("%s", s);
    for (j = 0; j < n; ++j) g[i][j] = (s[j] == '.');
  }
  g[0][n] = g[1][n] = 1;
  for (i = 0; i < 2; ++i)
    for (j = 0; j < n; ++j) d[i][j] = oo;
  ln = 0;
  for (j = i = 0; j < n; ++j, ++ln) {
    if (!g[i][j]) {
      i = (i + 1) % 2;
      ln = 0;
    }
    if (!g[i][j]) continue;
    d[i][j] = ln;
    if (!g[i][j + 1] && g[(i + 1) % 2][j]) {
      ++ln;
      i = (i + 1) % 2;
      d[i][j] = ln;
    }
  }
  for (i = 0; i < 2; ++i) l[i][0] = (g[i][0]) ? (-1) : 0;
  for (j = 1; j < n; ++j)
    for (i = 0; i < 2; ++i) l[i][j] = (g[i][j]) ? l[i][j - 1] : j;
  for (i = 0; i < 2; ++i) r[i][n] = n;
  for (j = n - 1; j >= 0; --j)
    for (i = 0; i < 2; ++i) r[i][j] = (g[i][j]) ? r[i][j + 1] : j;
  for (i = 0; i < 2; ++i) b[i][0] = !g[i][0];
  for (j = 1; j < n; ++j)
    for (i = 0; i < 2; ++i) b[i][j] = b[i][j - 1] + (!g[i][j]);
  for (i = 0; i < 2; ++i)
    for (j = 0; j < n; ++j) a[i][j] = oo;
  cl = 0;
  for (j = 0; j < n; ++j)
    for (i = 0; i < 2; ++i)
      if (g[i][j] && (a[i][j] == oo)) {
        dfs(i, j);
        ++cl;
      }
  for (u = 0; u < m; ++u) {
    scanf("%d%d", &c1, &c2);
    --c1;
    --c2;
    i1 = c1 / n;
    j1 = c1 % n;
    i2 = c2 / n;
    j2 = c2 % n;
    if (j1 > j2) {
      swap(i1, i2);
      swap(j1, j2);
    }
    if (a[i1][j1] != a[i2][j2]) {
      printf("-1\n");
      continue;
    }
    if (j1 == j2) {
      printf("%d\n", abs(i2 - i1));
      continue;
    }
    if ((i1 == i2) && (b[i1][j1] == b[i1][j2])) {
      printf("%d\n", j2 - j1);
      continue;
    }
    if ((j2 < r[i1][j1]) || (j1 > l[i2][j2])) {
      printf("%d\n", 1 + j2 - j1);
      continue;
    }
    an = r[i1][j1] - 1 - j1;
    j1 = r[i1][j1] - 1;
    if (d[i1][j1] == oo)
      an += 1 - d[(i1 + 1) % 2][j1];
    else
      an += -d[i1][j1];
    if (d[i2][j2] == oo)
      an += 1 + d[(i2 + 1) % 2][j2];
    else
      an += d[i2][j2];
    printf("%d\n", an);
  }
  return 0;
}
