#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector veci; typedef vector vecs; template using Hash=unordered_map; #define REP(i, a, n) for(ll i = a; i < n; i++) #define rep(i, n) REP(i, 0, n) template T read(){T a;cin >> a;return a;} template T read(T& a){cin >> a;} template void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}} template void write(T a){cout << a << endl;} void write(double a){cout << fixed << setprecision(12) << a << endl;} template void warr(T a, int n, char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;} ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}} int main(void) { int w,h,n; Hash* a=new Hash[1000*1000]; cin>>w>>h>>n; rep(i,n) { int m=read(); int bf=read(); rep(j,m){ int b=read(); int sign=(b q; int res[1000*1000]={0}; int WH=w*h-1; q.push(0); vis[0]=true; while(!q.empty()){ int cur=q.front(); q.pop(); for(auto p : a[cur]){ if(!vis[p.first]){ vis[p.first]=true; res[p.first]=res[cur]+1; q.push(p.first); } } if(vis[WH]) break; } if(vis[WH]) write(res[WH]); else write("Odekakedekinai.."); return 0; }