#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char matrix[2][N];
pair<int, int> dist[2][N][21];
void calcDist(int n) {
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j <= n; j++) {
      if (matrix[i][j] == 'X') continue;
      if (matrix[i][j + 1] != 'X') {
        dist[i][j][0] = {i, j + 1};
      } else if (matrix[i ^ 1][j] != 'X') {
        dist[i][j][0] = {i ^ 1, j};
      } else {
        dist[i][j][0] = {i, j};
      }
    }
  }
  for (int lgg = 1; lgg <= 20; lgg++) {
    for (int i = 0; i < 2; i++) {
      for (int j = 1; j <= n; j++) {
        if (matrix[i][j] == 'X') continue;
        auto nxt = dist[i][j][lgg - 1];
        dist[i][j][lgg] = dist[nxt.first][nxt.second][lgg - 1];
      }
    }
  }
}
int ff;
void dfs(int i, int j, int ei, int ej, int movee) {
  if (movee == 7) return;
  if (i == ei && j == ej) {
    ff = min(ff, movee);
    return;
  }
  if (matrix[i][j + 1] != 'X') dfs(i, j + 1, ei, ej, movee + 1);
  if (matrix[i ^ 1][j] != 'X') dfs(i ^ 1, j, ei, ej, movee + 1);
}
int getDist(int si, int sj, int ei, int ej) {
  int ans = 0;
  pair<int, int> cur = {si, sj};
  for (int lgg = 20; lgg >= 2; lgg--) {
    auto a = dist[cur.first][cur.second][lgg];
    if (lgg == 20 && a.second < ej) return -1;
    if (a.second >= ej) continue;
    ans += (1 << lgg);
    cur = a;
  }
  ff = 7;
  dfs(cur.first, cur.second, ei, ej, 0);
  return ans + ff;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(dist, -1, sizeof(dist));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 2; i++)
    for (int j = 1; j <= n; j++) cin >> matrix[i][j];
  matrix[0][n + 1] = matrix[1][n + 1] = 'X';
  calcDist(n);
  while (m--) {
    int st, en;
    cin >> st >> en;
    st--;
    en--;
    if (st > en) swap(st, en);
    int si, sj, ei, ej;
    if (st < n) {
      si = 0;
      sj = st;
    } else {
      si = 1;
      sj = st % n;
    }
    if (en < n) {
      ei = 0;
      ej = en;
    } else {
      ei = 1;
      ej = en % n;
    }
    if (sj > ej) {
      swap(si, ei);
      swap(sj, ej);
    }
    cout << getDist(si, sj + 1, ei, ej + 1) << "\n";
  }
  return 0;
}
