#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
int n, m;
string s[2];
int dp[18][maxn][2][2];
int solve(int a1, int b1, int a2, int b2) {
  int ans = -1;
  if (a1 != -1 && b1 != -1) {
    if (ans == -1)
      ans = a1 + b1;
    else
      ans = min(ans, a1 + b1);
  }
  if (a2 != -1 && b2 != -1) {
    if (ans == -1)
      ans = a2 + b2;
    else
      ans = min(ans, a2 + b2);
  }
  if (ans != -1) ++ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int _n(2), i(0); i < _n; i++) cin >> s[i];
  for (int _n(n), i(0); i < _n; i++) {
    dp[0][i][0][0] = s[0][i] == '.' ? 0 : -1;
    dp[0][i][1][1] = s[1][i] == '.' ? 0 : -1;
    dp[0][i][0][1] = dp[0][i][1][0] = s[0][i] == '.' && s[1][i] == '.' ? 1 : -1;
  }
  for (int _n(18), i(1); i < _n; i++) {
    int sz = 1 << i;
    int sz2 = 1 << (i - 1);
    for (int j = 0; j + sz <= n; ++j)
      for (int a = 0; a < 2; ++a)
        for (int b = 0; b < 2; ++b) {
          dp[i][j][a][b] = solve(dp[i - 1][j][a][0], dp[i - 1][j + sz2][0][b],
                                 dp[i - 1][j][a][1], dp[i - 1][j + sz2][1][b]);
        }
  }
  for (int _n(m), _(0); _ < _n; _++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    int c1 = x % n, c2 = y % n;
    int b1 = x / n, b2 = y / n;
    if (c2 < c1) {
      swap(c1, c2);
      swap(b1, b2);
    }
    int aux[2][2], aux2[2][2];
    for (int _n(2), i(0); i < _n; i++)
      for (int _n(2), j(0); j < _n; j++) aux[i][j] = dp[0][c1][i][j];
    int L = c2 - c1;
    int L2 = 1;
    while (L) {
      int x = __builtin_ctz(L);
      L ^= (1 << x);
      for (int b1 = 0; b1 <= 1; ++b1)
        for (int b2 = 0; b2 <= 1; ++b2) {
          aux2[b1][b2] = solve(aux[b1][0], dp[x][c1 + L2][0][b2], aux[b1][1],
                               dp[x][c1 + L2][1][b2]);
        }
      L2 += (1 << x);
      for (int b1 = 0; b1 <= 1; ++b1)
        for (int b2 = 0; b2 <= 1; ++b2) {
          aux[b1][b2] = aux2[b1][b2];
        }
    }
    cout << aux[b1][b2] << endl;
  }
  return 0;
}
