#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#define max 1005
using namespace std;
int grid[max][max]={0},r,c;
int si,sj,ei,ej;
queue<int> qi,qj;
void push_q(int i,int j) {
qi.push(i);
qj.push(j);
}
void pop_q() {
qi.pop();
qj.pop();
}
void adj(int u,int v) {
if( grid[u][v-1] == 0 && v>0) {
push_q(u,v-1);
grid[u][v-1] = grid[u][v]+1;
}
if( grid[u][v+1] == 0 && v<c) {
push_q(u,v+1);
grid[u][v+1] =grid[u][v]+1;
}
if( grid[u-1][v] == 0 && u>0) {
push_q(u-1,v);
grid[u-1][v] =grid[u][v]+1;
}
if( grid[u+1][v] == 0 && u<r) {
push_q(u+1,v);
grid[u+1][v] =grid[u][v]+1;
}
}
void print_q(queue<int> q){
int s;
while(!q.empty()){
s=q.front();
cout<<s<<", ";
q.pop();
}
cout<<endl;
}
void findpath(int si,int sj,int ei,int ej){
int u,v;
grid[si][sj] = 0;
push_q(si,sj);
while(!qi.empty() && !qj.empty()){
u=qi.front();
v=qj.front();
if(ei==u && ej==v) break;
pop_q();
adj(u,v);
}
}
void reset() {
int i,j;
while(!qi.empty() && !qj.empty()){
qi.pop();
qj.pop();
}
for(i=0;i<r;i++)
for(j=0;j<c;j++)
grid[i][j]=0;
}
int main(){
int i,j,t,row,col,n;
while(1) {
scanf("%d%d",&r,&c);
if(r==0 && c==0) break;
scanf("%d",&t);
for(i=0;i<t;i++) {
scanf("%d %d",&row,&n);
for(j=0;j<n;j++){
scanf("%d",&col);
grid[row][col] = 1;
}
}
scanf("%d%d",&si,&sj);
scanf("%d%d",&ei,&ej);
findpath(si,sj,ei,ej);
printf("%d\n",grid[ei][ej]);
reset();
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHF1ZXVlPgojaW5jbHVkZTxjc3RkaW8+CiNpbmNsdWRlPGNzdHJpbmc+CiNkZWZpbmUgbWF4IDEwMDUKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBncmlk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GUoIXFpLmVtcHR5KCkgJiYgIXFqLmVtcHR5KCkpewogICAgICB1PXFpLmZyb250KCk7CiAgICAgIHY9cWouZnJvbnQoKTsKICAgICAgaWYoZWk9PXUgJiYgZWo9PXYpIGJyZWFrOwogICAgICBwb3BfcSgpOwogICAgICBhZGoodSx2KTsKICB9Cn0KCnZvaWQgcmVzZXQoKSB7ICAgCiAgICAgaW50IGksajsKICAgICB3aGlsZSghcWkuZW1wdHkoKSAmJiAhcWouZW1wdHkoKSl7CiAgICAgICBxaS5wb3AoKTsKICAgICAgIHFqLnBvcCgpOwogICAgIH0KICAgICBmb3IoaT0wO2k8cjtpKyspCiAgICAgIGZvcihqPTA7ajxjO2orKykKICAgICAgICBncmlkW2ldW2pdPTA7Cn0KCmludCBtYWluKCl7CiBpbnQgaSxqLHQscm93LGNvbCxuOwogd2hpbGUoMSkgewogICBzY2FuZigiJWQlZCIsJnIsJmMpOwogICBpZihyPT0wICYmIGM9PTApIGJyZWFrOwogICBzY2FuZigiJWQiLCZ0KTsKICAgZm9yKGk9MDtpPHQ7aSsrKSB7CiAgICAgc2NhbmYoIiVkICVkIiwmcm93LCZuKTsKICAgICBmb3Ioaj0wO2o8bjtqKyspewogICAgICAgc2NhbmYoIiVkIiwmY29sKTsKICAgICAgIGdyaWRbcm93XVtjb2xdID0gMTsKICAgICB9IAogICB9CiAgIHNjYW5mKCIlZCVkIiwmc2ksJnNqKTsKICAgc2NhbmYoIiVkJWQiLCZlaSwmZWopOwogICBmaW5kcGF0aChzaSxzaixlaSxlaik7CiAgIHByaW50ZigiJWRcbiIsZ3JpZFtlaV1bZWpdKTsKICAgcmVzZXQoKTsKIH0KIHJldHVybiAwOyAgIAp9Cg==