#include <bits/stdc++.h>

#define endl '\n'
#define INF 0x3f3f3f3f

using namespace std;

typedef pair<int, int> pii;

inline int get_int(){
   int ch, i;
   while (((ch = getchar()) == ' ') || (ch == '\n'));
   for (i = 0; ch >= '0' && ch <= '9'; ch = getchar() )
       i = 10 * i + (ch - '0');
	return i;
}

const int MAXN = 1e3 + 10;

int C, L, W;
int Cr, Lr, Cs, Ls;
const int COSTS[5][5] = {
   {7, 6, 5, 6, 7},
   {6, 3, 2, 3, 6},
   {5, 2, 0, 2, 5},
   {6, 3, 2, 3, 6},
   {7, 6, 5, 6, 7},
};
bitset<MAXN> alagado[MAXN];
int g[MAXN][MAXN];

bool valid(int c, int l) {
   return c > 0 && c <= C && l > 0 && l <= L && alagado[c][l] == 0; 
}

int h(int c, int l) {
   return 0;
}

void solve()
{
   for (int i = 1; i <= C; i++){
      for (int j = 1; j <= L; j++){
         g[i][j] = INF;
      }
   }

    priority_queue<
      pair<int, pii>,
      vector<pair<int, pii>>,
      greater<>
    > pq;

   g[Cr][Lr] = 0;
   pq.push({h(Cr, Lr), {Cr, Lr}});

   while (!pq.empty()){
      auto [curCost, curCoords] = pq.top();
      pq.pop();

      auto [c, l] = curCoords;

      if (curCost != g[c][l] + h(c,l)) continue;

      if (c == Cs && l == Ls){
         cout << g[c][l] << endl;
         return;
      }

      for (int i = -2; i <= 2; i++){
         for (int j = -2; j <= 2; j++){
            int nc = c + i, nl = l + j;
            if (!valid(nc, nl)) continue;

            int cost = COSTS[i+2][j+2];
            int newG = g[c][l] + cost;

            if (newG < g[nc][nl]){
               g[nc][nl] = newG;
               pq.push({newG + h(nc, nl), {nc, nl}});
            }
         }
      }
   }

    cout << "impossible" << endl;
}

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(nullptr);

   while (C=get_int(), L=get_int(), C && L){
      Cr = get_int();
      Lr = get_int();
      Cs = get_int();
      Ls = get_int();
      for (int i = 1; i <= C; i++){
         for (int j = 1; j <= L; j++){
               alagado[i][j]=0;
         }
      }
      W = get_int();
      for (int i = 0; i < W; i++){
         int C1, C2, L1, L2;
         C1 = get_int();
         L1 = get_int();
         C2 = get_int();
         L2 = get_int();
         for (int k = C1; k <= C2; k++)
            for (int l = L1; l <= L2; l++)
               alagado[k][l] = 1;
      }
      solve();
   }
   return 0;
}