#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<string> v(2);
  for (auto& i : v) cin >> i;
  vector<pair<pair<long long, long long>, pair<long long, long long>>> seg(2 *
                                                                           n);
  auto comb =
      [](pair<pair<long long, long long>, pair<long long, long long>>& a,
         pair<pair<long long, long long>, pair<long long, long long>>& b)
      -> pair<pair<long long, long long>, pair<long long, long long>> {
    if (a.first.first == -1) return b;
    if (b.first.first == -1) return a;
    return {{1 + min(a.first.first + b.first.first,
                     a.first.second + b.second.first),
             1 + min(a.first.first + b.first.second,
                     a.first.second + b.second.second)},
            {1 + min(a.second.first + b.first.first,
                     a.second.second + b.second.first),
             1 + min(a.second.first + b.first.second,
                     a.second.second + b.second.second)}};
  };
  auto val = [](char c) -> long long { return c == '.' ? 0 : INF; };
  for (int i = 0; i < n; i++) {
    pair<pair<long long, long long>, pair<long long, long long>> x = {
        {val(v[0][i]), 1 + val(v[0][i]) + val(v[1][i])},
        {1 + val(v[0][i]) + val(v[1][i]), val(v[1][i])}};
    seg[n + i] = x;
  }
  for (int i = n - 1; i; i--) seg[i] = comb(seg[2 * i], seg[2 * i + 1]);
  while (q--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    int xa = a / n, ya = a % n;
    int xb = b / n, yb = b % n;
    if (ya > yb) swap(ya, yb), swap(xa, xb);
    pair<pair<long long, long long>, pair<long long, long long>> l = {{-1, -1},
                                                                      {-1, -1}};
    pair<pair<long long, long long>, pair<long long, long long>> r = {{-1, -1},
                                                                      {-1, -1}};
    for (ya += n, yb += n; ya <= yb; ++ya /= 2, --yb /= 2) {
      if (ya % 2 == 1) l = comb(l, seg[ya]);
      if (yb % 2 == 0) r = comb(seg[yb], r);
    }
    l = comb(l, r);
    long long ans;
    if (xa == 0 and xb == 0) ans = l.first.first;
    if (xa == 0 and xb == 1) ans = l.first.second;
    if (xa == 1 and xb == 0) ans = l.second.first;
    if (xa == 1 and xb == 1) ans = l.second.second;
    if (ans >= INF)
      cout << -1 << '\n';
    else
      cout << ans << '\n';
  }
  exit(0);
}
