#include <bits/stdc++.h>
using namespace std;
int N, M;
char B[200001][2];
int jmp[200001][2][2][20];
const int inf = 1e9;
void make_table() {
  for (int i = 1; i <= N; ++i) {
    for (int st = 0; st < 2; ++st) {
      for (int ed = 0; ed < 2; ++ed) {
        if (i < N && B[i][st] == '.' && B[i + 1][ed] == '.' && st == ed)
          jmp[i][st][ed][0] = 1;
        else
          jmp[i][st][ed][0] = inf;
      }
      for (int ed = 0; ed < 2; ++ed) {
        if (jmp[i][st][ed][0] < inf && jmp[i][st][!ed][0] == inf &&
            B[i + 1][!ed] == '.')
          jmp[i][st][!ed][0] = 2;
      }
    }
  }
  for (int i = 0; i < 19; ++i) {
    for (int p = 1; p <= N; ++p) {
      for (int st = 0; st < 2; ++st) {
        for (int ed = 0; ed < 2; ++ed) {
          jmp[p][st][ed][i + 1] = inf;
          if (p + (1 << i) > N) continue;
          jmp[p][st][ed][i + 1] =
              min(jmp[p][st][ed][i + 1],
                  jmp[p][st][0][i] + jmp[p + (1 << i)][0][ed][i]);
          jmp[p][st][ed][i + 1] =
              min(jmp[p][st][ed][i + 1],
                  jmp[p][st][1][i] + jmp[p + (1 << i)][1][ed][i]);
        }
        if (p + (1 << (i + 1)) <= N)
          for (int ed = 0; ed < 2; ++ed)
            if (B[p + (1 << (i + 1))][!ed] == '.')
              if (jmp[p][st][!ed][i + 1] > jmp[p][st][ed][i + 1] + 1)
                jmp[p][st][!ed][i + 1] = jmp[p][st][ed][i + 1] + 1;
      }
    }
  }
}
int query(int x, int y) {
  int rowX = (x > N), colX = x - rowX * N;
  int rowY = (y > N), colY = y - rowY * N;
  if (colX > colY) swap(colX, colY), swap(rowX, rowY);
  int f[21][2];
  f[20][rowX] = 0;
  f[20][!rowX] = (B[colX][!rowX] == '.' ? 1 : inf);
  int cur = colX;
  for (int i = 19; i >= 0; --i)
    for (int j = 0; j < 2; ++j) {
      f[i][j] = inf;
      if ((colY - colX) & (1 << i)) {
        for (int k = 0; k < 2; ++k)
          f[i][j] = min(f[i][j], f[i + 1][k] + jmp[cur][k][j][i]);
        if (j) cur += (1 << i);
      } else
        f[i][j] = f[i + 1][j];
    }
  return f[0][rowY];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < 2; ++i)
    for (int j = 1; j <= N; ++j) cin >> B[j][i];
  make_table();
  while (M--) {
    int x, y;
    cin >> x >> y;
    int ans = query(x, y);
    printf("%d\n", (ans == inf ? -1 : ans));
  }
}
