#include <bits/stdc++.h>
using namespace std;
const long INF = 1000000, CINF = 600000;
long gx[550002][2][2], llt[550002], rlt[550002];
char ch[200002][2];
long f0, f1, l, r;
bool ff;
void update(long now, long mid) {
  if (ch[mid][0] == '.' && ch[mid + 1][0] == '.') {
    gx[now][0][0] =
        min(gx[now][0][0], gx[(now * 2)][0][0] + 1 + gx[(now * 2 + 1)][0][0]);
    gx[now][1][0] =
        min(gx[now][1][0], gx[(now * 2)][1][0] + 1 + gx[(now * 2 + 1)][0][0]);
    gx[now][0][1] =
        min(gx[now][0][1], gx[(now * 2)][0][0] + 1 + gx[(now * 2 + 1)][0][1]);
    gx[now][1][1] =
        min(gx[now][1][1], gx[(now * 2)][1][0] + 1 + gx[(now * 2 + 1)][0][1]);
  }
  if (ch[mid][1] == '.' && ch[mid + 1][1] == '.') {
    gx[now][0][0] =
        min(gx[now][0][0], gx[(now * 2)][0][1] + 1 + gx[(now * 2 + 1)][1][0]);
    gx[now][1][0] =
        min(gx[now][1][0], gx[(now * 2)][1][1] + 1 + gx[(now * 2 + 1)][1][0]);
    gx[now][0][1] =
        min(gx[now][0][1], gx[(now * 2)][0][1] + 1 + gx[(now * 2 + 1)][1][1]);
    gx[now][1][1] =
        min(gx[now][1][1], gx[(now * 2)][1][1] + 1 + gx[(now * 2 + 1)][1][1]);
  }
  llt[now] = llt[(now * 2)];
  rlt[now] = rlt[(now * 2 + 1)];
}
void build(long now, long s, long t) {
  long mid = (s + t) / 2;
  if (s == t) {
    if (ch[s][0] == '.')
      gx[now][0][0] = 0;
    else
      gx[now][0][0] = INF;
    if (ch[s][1] == '.')
      gx[now][1][1] = 0;
    else
      gx[now][1][1] = INF;
    if (ch[s][0] == '.' && ch[s][1] == '.') {
      gx[now][0][1] = gx[now][1][0] = llt[now] = rlt[now] = 1;
    } else
      gx[now][0][1] = gx[now][1][0] = llt[now] = rlt[now] = INF;
    return;
  }
  build((now * 2), s, mid);
  build((now * 2 + 1), mid + 1, t);
  gx[now][0][0] = gx[now][0][1] = gx[now][1][0] = gx[now][1][1] = INF;
  update(now, mid);
}
void query(long now, long s, long t) {
  long mid = (s + t) / 2, t0, t1;
  if (l <= s && t <= r) {
    if (!ff) return;
    if (ch[s][0] == '.')
      f0++;
    else
      f0 = INF;
    if (ch[s][1] == '.')
      f1++;
    else
      f1 = INF;
    t0 = f0;
    t1 = f1;
    f0 = min(t0 + gx[now][0][0], t1 + gx[now][1][0]);
    f1 = min(t1 + gx[now][1][1], t0 + gx[now][0][1]);
    if (f0 >= CINF && f1 >= CINF) ff = false;
    return;
  }
  if (l <= mid) query((now * 2), s, mid);
  if (mid < r) query((now * 2 + 1), mid + 1, t);
}
int main() {
  long i, j, m, n, x, y, ans;
  char ch1;
  scanf("%ld%ld", &n, &m);
  ch1 = ' ';
  while (ch1 != '\n') scanf("%c", &ch1);
  for (i = 1; i <= n; i++) scanf("%c", &ch[i][0]);
  ch1 = ' ';
  while (ch1 != '\n') scanf("%c", &ch1);
  for (i = 1; i <= n; i++) scanf("%c", &ch[i][1]);
  build(1, 1, n);
  for (i = 1; i <= m; i++) {
    scanf("%ld%ld", &x, &y);
    ff = true;
    if ((x - 1) % n + 1 == (y - 1) % n + 1) {
      l = (x - 1) % n + 1;
      r = (x > n);
      if (x == y) {
        if (ch[l][r] == '.')
          printf("0\n");
        else
          printf("-1\n");
      } else {
        if (ch[l][r] == '.' && ch[l][r ^ 1] == '.')
          printf("1\n");
        else
          printf("-1\n");
      }
      continue;
    }
    if ((x - 1) % n + 1 > (y - 1) % n + 1) {
      long t = x;
      x = y;
      y = t;
    }
    if (x <= n) {
      f0 = -1;
      f1 = INF;
    } else {
      f0 = INF;
      f1 = -1;
    }
    l = (x - 1) % n + 1;
    r = (y - 1) % n + 1;
    query(1, 1, n);
    if (y <= n)
      ans = f0;
    else
      ans = f1;
    if (ff)
      printf("%ld\n", ans);
    else
      printf("-1\n");
  }
  return 0;
}
