#include <bits/stdc++.h>
using namespace std;
const long long mod7 = 1000000007;
int n, m;
int sz;
string s[2];
vector<int> gr[200000];
int num[2][300002];
bool used[300002];
int dist[300002];
int lca[300002][30];
int l = 20;
int timer;
int tin[300002];
int tout[300002];
int cnt[300002];
int ccnt = 1;
void dfs(int v, int p, int depth) {
  used[v] = true;
  tin[v] = timer++;
  lca[v][0] = p;
  for (int i = 1; i < l; ++i) lca[v][i] = lca[lca[v][i - 1]][i - 1];
  for (int i = 0; i < gr[v].size(); ++i) {
    if (!used[gr[v][i]]) dfs(gr[v][i], v, depth + 1);
  }
  cnt[v] = ccnt;
  dist[v] = depth;
  tout[v] = timer++;
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int find_lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = l - 1; i >= 0; --i)
    if (!upper(lca[a][i], b)) a = lca[a][i];
  return lca[a][0];
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> s[0] >> s[1];
  for (int j = 0; j < 2; ++j) {
    for (int i = 0; i < s[j].length(); ++i) {
      num[j][i] = -1;
      if (s[j][i] == '.')
        num[j][i] = sz;
      else if (i && s[j][i - 1] == '.')
        ++sz;
    }
    ++sz;
  }
  int j = 0;
  for (int i = 0; i < s[j].length(); ++i) {
    if (s[j][i] == '.' && s[1 - j][i] == '.') {
      gr[num[j][i]].push_back(num[1 - j][i]);
      gr[num[1 - j][i]].push_back(num[j][i]);
    }
  }
  for (int i = 0; i < sz; ++i) {
    if (!used[i]) {
      dfs(i, i, 0);
      ++ccnt;
    }
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    int temp = abs((a <= n ? a - 1 : a - n - 1) - (b <= n ? b - 1 : b - n - 1));
    a = num[a <= n ? 0 : 1][a <= n ? a - 1 : a - n - 1];
    b = num[b <= n ? 0 : 1][b <= n ? b - 1 : b - n - 1];
    if (cnt[a] != cnt[b])
      cout << -1 << endl;
    else {
      int z = find_lca(a, b);
      cout << (dist[a] + dist[b] - 2 * dist[z] + temp) << endl;
    }
  }
  return 0;
}
