#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long MOD = (long long)1e9 + 7;
const long double pi = atan2(0, -1);
const long long N = 1000000;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  int n, m;
  cin >> n >> m;
  char a[2][n];
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  int sz = 0;
  while ((1 << sz) <= n) sz++;
  vector<vector<vector<int> > > dist(
      sz, vector<vector<int> >(n, vector<int>(4, inf)));
  for (int i = 0; i < n; i++) {
    if (a[0][i] == '.') dist[0][i][0] = 0;
    if (a[1][i] == '.') dist[0][i][3] = 0;
    if (a[0][i] == '.' && a[1][i] == '.') {
      dist[0][i][1] = 1;
      dist[0][i][2] = 1;
    }
  }
  for (int j = 1; j < sz; j++)
    for (int i = 0; i + (1 << j) <= n; i++) {
      dist[j][i][0] =
          min(dist[j - 1][i][0] + dist[j - 1][i + (1 << (j - 1))][0],
              dist[j - 1][i][1] + dist[j - 1][i + (1 << (j - 1))][2]) +
          1;
      dist[j][i][1] =
          min(dist[j - 1][i][0] + dist[j - 1][i + (1 << (j - 1))][1],
              dist[j - 1][i][1] + dist[j - 1][i + (1 << (j - 1))][3]) +
          1;
      dist[j][i][2] =
          min(dist[j - 1][i][2] + dist[j - 1][i + (1 << (j - 1))][0],
              dist[j - 1][i][3] + dist[j - 1][i + (1 << (j - 1))][2]) +
          1;
      dist[j][i][3] =
          min(dist[j - 1][i][3] + dist[j - 1][i + (1 << (j - 1))][3],
              dist[j - 1][i][2] + dist[j - 1][i + (1 << (j - 1))][1]) +
          1;
      for (int l = 0; l < 4; l++) dist[j][i][l] = min(dist[j][i][l], inf);
    }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (u % n > v % n) swap(u, v);
    int x1 = u / n, x2 = v / n;
    u %= n;
    v %= n;
    int k = v - u;
    vector<int> d1 = dist[0][u], d2(4);
    u++;
    for (int j = 0; j < 18; j++)
      if ((k >> j) & 1) {
        d2[0] = min(d1[0] + dist[j][u][0], d1[1] + dist[j][u][2]) + 1;
        d2[1] = min(d1[0] + dist[j][u][1], d1[1] + dist[j][u][3]) + 1;
        d2[2] = min(d1[2] + dist[j][u][0], d1[3] + dist[j][u][2]) + 1;
        d2[3] = min(d1[3] + dist[j][u][3], d1[2] + dist[j][u][1]) + 1;
        d1 = d2;
        for (int l = 0; l < 4; l++) d1[l] = min(d1[l], inf);
        u += (1 << j);
      }
    cout << (d1[x1 * 2 + x2] != inf ? d1[x1 * 2 + x2] : -1) << endl;
  }
  return 0;
}
