#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 2e5 + 5;
char g[2][N];
vector<pair<int, int> > qur[2][2][N];
int ans[N];
long long tree[4 * N], lazy[4 * N];
bool row[4 * N], lz[4 * N];
void propogate(int i, int l, int r) {
  if (!lazy[i]) return;
  tree[i] += lazy[i];
  row[i] = lz[i];
  if (l != r) {
    lazy[i << 1] += lazy[i];
    lazy[i << 1 | 1] += lazy[i];
    lz[i << 1] = lz[i << 1 | 1] = lz[i];
  }
  lazy[i] = lz[i] = 0;
}
void update(int i, int l, int r, int a, int b, bool f, int v) {
  propogate(i, l, r);
  if (l > b || r < a) return;
  if (l >= a && r <= b) {
    lazy[i] += v;
    lz[i] = f;
    propogate(i, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  update(i << 1, l, mid, a, b, f, v);
  update(i << 1 | 1, mid + 1, r, a, b, f, v);
}
pair<long long, int> get(int i, int l, int r, int a) {
  propogate(i, l, r);
  if (l > a || r < a) return make_pair(1e8, 0);
  if (l == r) return make_pair(tree[i], row[i]);
  int mid = (l + r) >> 1;
  return min(get(i << 1, l, mid, a), get(i << 1 | 1, mid + 1, r, a));
}
void solve(bool f) {
  int last = 0;
  for (int i = 1; i <= n; i++) {
    for (int k = 0; k < 2; k++) {
      for (int j = 0; j < qur[f][k][i].size(); j++) {
        int u = qur[f][k][i][j].first;
        int indx = qur[f][k][i][j].second;
        if (g[f][u] == 'X' || g[k][i] == 'X')
          ans[indx] = -1;
        else {
          pair<int, int> dist = get(1, 1, n, u);
          ans[indx] = dist.first + (dist.second != k);
          if (ans[indx] >= 1e7) ans[indx] = -1;
        }
      }
    }
    if ((g[f][i + 1] == 'X' && g[!f][i] == 'X') ||
        (g[f][i + 1] == 'X' && g[!f][i + 1] == 'X')) {
      update(1, 1, n, 1, i, 0, 1e8);
      last = i;
      continue;
    }
    if (last != 0) {
      if (g[!f][i + 1] != 'X')
        update(1, 1, n, 1, last, !f, 1);
      else if ((g[!f][i + 1] == 'X' && g[f][i] == 'X') ||
               (g[f][i + 1] == 'X' && g[!f][i + 1] == 'X')) {
        update(1, 1, n, 1, last, 0, 1e8);
        last = i;
        continue;
      } else {
        update(1, 1, n, 1, last, f, 1);
        last = 0;
      }
    }
    if (g[f][i + 1] != 'X')
      update(1, 1, n, last + 1, i, f, 1);
    else {
      update(1, 1, n, last + 1, i, !f, 2);
      last = i;
    }
  }
}
int fix(int u) {
  if (u > n) return u - n;
  return u;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(ans, -1, sizeof ans);
  cin >> n >> m;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) cin >> g[i][j + 1];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (fix(v) < fix(u))
      qur[v > n][u > n][fix(u)].push_back(make_pair(fix(v), i));
    else
      qur[u > n][v > n][fix(v)].push_back(make_pair(fix(u), i));
  }
  solve(0);
  for (int i = 0; i < 4 * N; i++) tree[i] = lazy[i] = lz[i] = 0, row[i] = 1;
  solve(1);
  for (int i = 0; i < m; i++) cout << ans[i] << '\n';
  return 0;
}
