#include <bits/stdc++.h>
using namespace std;
int n, Q, cc, dd[3][200005], dist[200005], a[3][200005];
vector<int> all;
int fx[4] = {0, 1, 0, -1};
int fy[4] = {1, 0, -1, 0};
void DFS(int u, int v) {
  dd[u][v] = cc;
  for (int i = 0; i < 4; i++) {
    int x = u + fx[i];
    int y = v + fy[i];
    if (x < 1 || x > 2 || y < 1 || y > n || dd[x][y] || a[x][y]) continue;
    DFS(x, y);
  }
}
void convert(int u, int &x, int &y) {
  x = (u - 1) / n + 1;
  y = u - (x - 1) * n;
}
int solve(int u, int v) {
  int x1, x2, y1, y2;
  convert(u, y1, x1);
  convert(v, y2, x2);
  if (x1 > x2) swap(x1, x2), swap(y1, y2);
  if (dd[y1][x1] != dd[y2][x2]) return -1;
  if (x1 == x2) return abs(y1 - y2);
  int pos1 = lower_bound(all.begin(), all.end(), x1) - all.begin();
  int pos2 = upper_bound(all.begin(), all.end(), x2) - all.begin() - 1;
  if (pos1 > pos2) return abs(x1 - x2) + abs(y1 - y2);
  int ans = dist[pos2] - dist[pos1] + (all[pos1] - x1) + (x2 - all[pos2]);
  if (a[y1][all[pos1]] == 1) ans++;
  if (a[y2][all[pos2]] == 1) ans++;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> Q;
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++) {
      char c;
      cin >> c;
      a[i][j] = (c == '.') ? 0 : 1;
    }
  for (int i = 1; i <= n; i++)
    if (a[1][i] + a[2][i] == 1) all.push_back(i);
  dist[0] = 0;
  for (int i = 1; i < all.size(); i++)
    dist[i] = dist[i - 1] + (all[i] - all[i - 1]) +
              (a[1][all[i]] != a[1][all[i - 1]]);
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++)
      if (!dd[i][j] && a[i][j] == 0) {
        cc++;
        DFS(i, j);
      }
  while (Q--) {
    int u, v;
    cin >> u >> v;
    cout << solve(u, v) << '\n';
  }
}
