#include <bits/stdc++.h>
using namespace std;
const int SZ = 2e5 + 100;
const int INF = 1e9 + 100;
struct node {
  int msk1;
  int msk2;
  int wall;
  int k1, k2, k3, k4;
  int empt;
  node() { empt = 0; }
};
node t[4 * SZ];
int a[2][SZ];
node merge(node a, node b) {
  if (a.empt) {
    return b;
  }
  if (b.empt) {
    return a;
  }
  if (a.wall) {
    return a;
  }
  if (b.wall) {
    return b;
  }
  node ans;
  ans.wall = 0;
  ans.msk1 = a.msk1;
  ans.msk2 = b.msk2;
  if (a.msk2 == 0) {
    if (b.msk1 == 0) {
      ans.k1 = min(a.k1 + b.k1 + 1, a.k2 + b.k3 + 1);
      ans.k2 = min(a.k1 + b.k2 + 1, a.k2 + b.k4 + 1);
      ans.k3 = min(a.k3 + b.k1 + 1, a.k4 + b.k3 + 1);
      ans.k4 = min(a.k3 + b.k2 + 1, a.k4 + b.k4 + 1);
    } else if (b.msk1 == 1) {
      ans.k1 = a.k2 + b.k3 + 1;
      ans.k2 = a.k2 + b.k4 + 1;
      ans.k3 = a.k4 + b.k3 + 1;
      ans.k4 = a.k4 + b.k4 + 1;
    } else {
      ans.k1 = a.k1 + b.k1 + 1;
      ans.k2 = a.k1 + b.k2 + 1;
      ans.k3 = a.k3 + b.k1 + 1;
      ans.k4 = a.k3 + b.k2 + 1;
    }
  } else if (a.msk2 == 1) {
    if (b.msk1 == 0) {
      ans.k1 = a.k2 + b.k3 + 1;
      ans.k2 = a.k2 + b.k4 + 1;
      ans.k3 = a.k4 + b.k3 + 1;
      ans.k4 = a.k4 + b.k4 + 1;
    } else if (b.msk1 == 1) {
      ans.k1 = a.k2 + b.k3 + 1;
      ans.k2 = a.k2 + b.k4 + 1;
      ans.k3 = a.k4 + b.k3 + 1;
      ans.k4 = a.k4 + b.k4 + 1;
    } else {
      ans.wall = 1;
    }
  } else {
    if (b.msk1 == 0) {
      ans.k1 = a.k1 + b.k1 + 1;
      ans.k2 = a.k1 + b.k2 + 1;
      ans.k3 = a.k3 + b.k1 + 1;
      ans.k4 = a.k3 + b.k2 + 1;
    } else if (b.msk1 == 1) {
      ans.wall = 1;
    } else {
      ans.k1 = a.k1 + b.k1 + 1;
      ans.k2 = a.k1 + b.k2 + 1;
      ans.k3 = a.k3 + b.k1 + 1;
      ans.k4 = a.k3 + b.k2 + 1;
    }
  }
  if (ans.k1 > INF) {
    ans.k1 = INF;
  }
  if (ans.k2 > INF) {
    ans.k2 = INF;
  }
  if (ans.k3 > INF) {
    ans.k3 = INF;
  }
  if (ans.k4 > INF) {
    ans.k4 = INF;
  }
  return ans;
}
void init(int v, int l, int r) {
  if (r - l == 1) {
    if (a[0][l] && a[1][l]) {
      t[v].wall = 1;
    } else if (a[0][l]) {
      t[v].msk1 = t[v].msk2 = 1;
      t[v].k4 = 0;
      t[v].k2 = INF;
      t[v].k3 = INF;
      t[v].k1 = INF;
      t[v].wall = 0;
    } else if (a[1][l]) {
      t[v].msk1 = t[v].msk2 = 2;
      t[v].k1 = 0;
      t[v].k4 = INF;
      t[v].k2 = INF;
      t[v].k3 = INF;
      t[v].wall = 0;
    } else {
      t[v].msk1 = t[v].msk2 = 0;
      t[v].k1 = t[v].k4 = 0;
      t[v].k2 = t[v].k3 = 1;
      t[v].wall = 0;
    }
    return;
  }
  int m = (l + r) / 2;
  init(2 * v + 1, l, m);
  init(2 * v + 2, m, r);
  t[v] = merge(t[2 * v + 1], t[2 * v + 2]);
}
node query(int v, int l, int r, int L, int R) {
  if (l >= R || L >= r) {
    node ans;
    ans.empt = 1;
    return ans;
  }
  if (l == L && r == R) {
    return t[v];
  }
  int m = (l + r) / 2;
  node t1 = query(2 * v + 1, l, m, max(l, L), min(m, R));
  node t2 = query(2 * v + 2, m, r, max(m, L), min(r, R));
  return merge(t1, t2);
}
void print(int k) {
  if (k >= INF) {
    cout << -1 << endl;
  } else {
    cout << k << endl;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      char ch;
      cin >> ch;
      if (ch == 'X') {
        a[i][j] = 1;
      }
    }
  }
  init(0, 0, n);
  for (int i = 0; i < m; i++) {
    int p1, p2;
    cin >> p1 >> p2;
    p1--;
    p2--;
    int l = p1 % n;
    int r = p2 % n;
    if (l > r) {
      swap(l, r);
      swap(p1, p2);
    }
    node res = query(0, 0, n, l, r + 1);
    if (res.wall) {
      cout << -1 << endl;
      continue;
    }
    if (p1 < n) {
      if (p2 < n) {
        print(res.k1);
      } else {
        print(res.k2);
      }
    } else {
      if (p2 < n) {
        print(res.k3);
      } else {
        print(res.k4);
      }
    }
  }
  return 0;
}
