#include <bits/stdc++.h>
using namespace std;
int N, M;
int Count;
int Num;
int A[2][200000 + 1], D[2][200000 + 1];
int Team[400000 + 1];
int DD[400000 + 1], NumIn[400000 + 1], NumOut[400000 + 1], Dis[400000 + 1];
int Pa[400000 + 1][20];
vector<int> Ke[400000 + 1];
int FindTeam(int X) {
  if (Team[X] > 0) {
    Team[X] = FindTeam(Team[X]);
    return Team[X];
  }
  return X;
}
void Union(int X, int Y) {
  int TeamX = FindTeam(X);
  int TeamY = FindTeam(Y);
  if (TeamX != TeamY) {
    if (Team[TeamX] < Team[TeamY]) {
      Team[TeamX] += Team[TeamY];
      Team[TeamY] = TeamX;
    } else {
      Team[TeamY] += Team[TeamX];
      Team[TeamX] = TeamY;
    }
    Ke[X].push_back(Y);
    Ke[Y].push_back(X);
  }
}
void DFS(int Pos) {
  DD[Pos] = 1;
  Num++;
  NumIn[Pos] = Num;
  for (int j = 1; j < 20; j++) {
    Pa[Pos][j] = Pa[Pa[Pos][j - 1]][j - 1];
  }
  for (int i = 0; i < int(Ke[Pos].size()); i++) {
    int v = Ke[Pos][i];
    if (Pa[Pos][0] != v) {
      Pa[v][0] = Pos;
      Dis[v] = Dis[Pos] + 1;
      DFS(v);
    }
  }
  Num++;
  NumOut[Pos] = Num;
}
bool IsPa(int X, int Y) {
  return ((NumIn[X] <= NumIn[Y]) && (NumOut[X] >= NumOut[Y]));
}
int LCA(int X, int Y) {
  if (IsPa(X, Y)) {
    return X;
  }
  if (IsPa(Y, X)) {
    return Y;
  }
  int CPa = X;
  for (int i = 19; i >= 0; i--) {
    if (!IsPa(Pa[CPa][i], Y)) {
      CPa = Pa[CPa][i];
    }
  }
  CPa = Pa[CPa][0];
  return CPa;
}
int Get(int X, int Y) {
  int Z = LCA(X, Y);
  return (Dis[X] + Dis[Y] - 2 * Dis[Z]);
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j <= N; j++) {
      char Kt;
      cin >> Kt;
      if (Kt == 'X') {
        A[i][j] = 1;
      } else {
        A[i][j] = 0;
      }
    }
  }
  Count = 0;
  for (int i = 0; i < 2; i++) {
    Count++;
    for (int j = 1; j <= N; j++) {
      if (A[i][j] == 1) {
        Count++;
      } else {
        D[i][j] = Count;
      }
    }
  }
  for (int i = 1; i <= Count; i++) {
    Team[i] = -1;
  }
  for (int j = 1; j <= N; j++) {
    if ((A[0][j] == 0) && (A[1][j] == 0)) {
      Union(D[0][j], D[1][j]);
    }
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j <= N; j++) {
      if ((A[i][j] == 0) && (DD[D[i][j]] == 0)) {
        Pa[D[i][j]][0] = D[i][j];
        Dis[D[i][j]] = 1;
        DFS(D[i][j]);
      }
    }
  }
  for (int i = 1; i <= M; i++) {
    int X, Y;
    cin >> X >> Y;
    int Hx, Cx, Hy, Cy;
    if (X <= N) {
      Hx = 0;
      Cx = X;
    } else {
      Hx = 1;
      Cx = X - N;
    }
    if (Y <= N) {
      Hy = 0;
      Cy = Y;
    } else {
      Hy = 1;
      Cy = Y - N;
    }
    if (FindTeam(D[Hx][Cx]) != FindTeam(D[Hy][Cy])) {
      cout << "-1" << endl;
    } else {
      cout << Get(D[Hx][Cx], D[Hy][Cy]) + abs(Cx - Cy) << endl;
    }
  }
  return 0;
}
