#include <iostream>
#include <algorithm>
using namespace std;

const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int w,h,n,sx,sy,gx,gy,d;
bool G[202][202];

void initG(){
  fill(G[0],G[202],false);
  for(int i=0;i<2*h+1;i++) G[i][0] = G[i][2*w] = true;
  for(int i=0;i<2*w+1;i++) G[0][i] = G[2*h][i] = true;
}

void displayG(int x, int y){
    for(int i=0;i<2*h+1;i++){
      for(int j=0;j<2*w+1;j++){
	if(i == y && x == j) cout << '*' << ' ';
	else cout << G[i][j] << ' ';
      }
      cout << endl;
    }
    cout << endl;
}

void solve(){
  int x = sx, y = sy, ans = 1;
  bool f[202][202][4];

  if(sx == gx && sy == gy){
    cout << 1 << endl;
    return;
  }


  for(int i=0;i<202;i++) for(int j=0;j<202;j++) for(int k=0;k<4;k++) f[i][j][k] = false;
  f[x][y][d] = true;

  while(1){
    bool f2 = false;
    for(int i=-1;i<=2;i++){
      int nd = (d + i + 4) % 4;
      int nx = x + dx[nd];
      int ny = y + dy[nd];

      if(G[ny][nx]) continue;

      nx += dx[nd];
      ny += dy[nd];
      if(f[nx][ny][nd]) break;

      x = nx;
      y = ny;
      d = nd;
      ans++;
      f[x][y][nd] = true;
      f2 = true;

      //displayG(x,y);

      if(x == gx && y == gy){
	cout << ans << endl;
	return;
      }

      break;
    }
    if(!f2) break;
  }
  cout << "Impossible" << endl;
}

int main(){
  int x1,y1,x2,y2;
  while(cin >> w >> h >> n && (w|h|n)){
    initG();

    for(int i=0;i<n;i++){
      cin >> x1 >> y1 >> x2 >> y2;
      if(x1 > x2) swap(x1,x2);
      if(y1 > y2) swap(y1,y2);
      if(x1 == x2) for(int j=2*y1;j<=2*y2;j++) G[j][2*x1] = true;
      if(y1 == y2) for(int j=2*x1;j<=2*x2;j++) G[2*y1][j] = true;
      //displayG();
    }

    cin >> x1 >> y1 >> x2 >> y2 >> gx >> gy;
    if(x1 > x2) swap(x1,x2);
    if(y1 > y2) swap(y1,y2);
    sx = x1 * 2 + 1;
    sy = y1 * 2 + 1;
    if(x1 == x2){
      if(x1 == 0) d = 1;
      else{
	d = 3;
	sx -= 2;
      }
    } else {
      if(y1 == 0) d = 0;
      else {
	d = 2;
	sy -= 2;
      }
    }

    gx = gx * 2 + 1;
    gy = gy * 2 + 1;
    //cout << sx << ' ' << sy << ' ' << d << endl;
    solve();
  }
}
### Prompt

Please provide a Cpp coded solution to the problem described below:

The left-hand rule, which is also known as the wall follower, is a well-known strategy that solves a two- dimensional maze. The strategy can be stated as follows: once you have entered the maze, walk around with keeping your left hand in contact with the wall until you reach the goal. In fact, it is proven that this strategy solves some kind of mazes.

Your task is to write a program that determines whether the given maze is solvable by using the left-hand rule and (if the maze is solvable) the number of steps to reach the exit. Moving to a cell from the entrance or the adjacent (north, south, east or west) cell is counted as a step.

In this problem, the maze is represented by a collection of walls placed on the two-dimensional grid. We use an ordinary Cartesian coordinate system; the positive x-axis points right and the positive y-axis points up. Each wall is represented by a line segment which is parallel to the x-axis or the y-axis, such that both ends of each wall are located on integer coordinates. The size of the maze is given by W and H that indicate the width and the height of the maze, respectively. A rectangle whose vertices are on (0, 0), (W, 0), (W, H) and (0, H) forms the outside boundary of the maze. The outside of the maze is always surrounded by walls except for the entrance of the maze. The entrance is represented by a line segment whose ends are (xE, yE) and (xE', yE'). The entrance has a unit length and is located somewhere on one edge of the boundary. The exit is a unit square whose bottom left corner is located on (xX, yX).

A few examples of mazes are illustrated in the figure below. They correspond to the datasets in the sample input.

<image>

Figure 1: Example Mazes (shaded squares indicate the exits)



Input

The input consists of multiple datasets.

Each dataset is formatted as follows:


W H N
x1 y1 x1' y1'
x2 y2 x2' y2'
...
xN yN xN' yN'
xE yE xE' yE' xX yX


W and H (0 < W, H ≤ 100) indicate the size of the maze. N is the number of walls inside the maze. The next N lines give the positions of the walls, where (xi, yi) and (xi', yi') denote two ends of each wall (1 ≤ i ≤ N). The last line gives the positions of the entrance and the exit. You can assume that all the coordinates given in the input are integer coordinates and located inside the boundary of the maze. You can also assume that the wall description is not redundant, i.e. an endpoint of a wall is not shared by any other wall that is parallel to it.

The input is terminated by a line with three zeros.

Output

For each dataset, print a line that contains the number of steps required to reach the exit. If the given maze is unsolvable, print “Impossible” instead of the number of steps.

Example

Input

3 3 3
1 0 1 2
1 2 2 2
2 2 2 1
0 0 1 0 1 1
3 3 4
1 0 1 2
1 2 2 2
2 2 2 1
2 1 1 1
0 0 1 0 1 1
3 3 0
0 0 1 0 1 1
0 0 0


Output

9
Impossible
Impossible

### Response

```cpp
#include <iostream>
#include <algorithm>
using namespace std;

const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int w,h,n,sx,sy,gx,gy,d;
bool G[202][202];

void initG(){
  fill(G[0],G[202],false);
  for(int i=0;i<2*h+1;i++) G[i][0] = G[i][2*w] = true;
  for(int i=0;i<2*w+1;i++) G[0][i] = G[2*h][i] = true;
}

void displayG(int x, int y){
    for(int i=0;i<2*h+1;i++){
      for(int j=0;j<2*w+1;j++){
	if(i == y && x == j) cout << '*' << ' ';
	else cout << G[i][j] << ' ';
      }
      cout << endl;
    }
    cout << endl;
}

void solve(){
  int x = sx, y = sy, ans = 1;
  bool f[202][202][4];

  if(sx == gx && sy == gy){
    cout << 1 << endl;
    return;
  }


  for(int i=0;i<202;i++) for(int j=0;j<202;j++) for(int k=0;k<4;k++) f[i][j][k] = false;
  f[x][y][d] = true;

  while(1){
    bool f2 = false;
    for(int i=-1;i<=2;i++){
      int nd = (d + i + 4) % 4;
      int nx = x + dx[nd];
      int ny = y + dy[nd];

      if(G[ny][nx]) continue;

      nx += dx[nd];
      ny += dy[nd];
      if(f[nx][ny][nd]) break;

      x = nx;
      y = ny;
      d = nd;
      ans++;
      f[x][y][nd] = true;
      f2 = true;

      //displayG(x,y);

      if(x == gx && y == gy){
	cout << ans << endl;
	return;
      }

      break;
    }
    if(!f2) break;
  }
  cout << "Impossible" << endl;
}

int main(){
  int x1,y1,x2,y2;
  while(cin >> w >> h >> n && (w|h|n)){
    initG();

    for(int i=0;i<n;i++){
      cin >> x1 >> y1 >> x2 >> y2;
      if(x1 > x2) swap(x1,x2);
      if(y1 > y2) swap(y1,y2);
      if(x1 == x2) for(int j=2*y1;j<=2*y2;j++) G[j][2*x1] = true;
      if(y1 == y2) for(int j=2*x1;j<=2*x2;j++) G[2*y1][j] = true;
      //displayG();
    }

    cin >> x1 >> y1 >> x2 >> y2 >> gx >> gy;
    if(x1 > x2) swap(x1,x2);
    if(y1 > y2) swap(y1,y2);
    sx = x1 * 2 + 1;
    sy = y1 * 2 + 1;
    if(x1 == x2){
      if(x1 == 0) d = 1;
      else{
	d = 3;
	sx -= 2;
      }
    } else {
      if(y1 == 0) d = 0;
      else {
	d = 2;
	sy -= 2;
      }
    }

    gx = gx * 2 + 1;
    gy = gy * 2 + 1;
    //cout << sx << ' ' << sy << ' ' << d << endl;
    solve();
  }
}
```