#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

string t[] = {
  "111101101101111",
  "",
  "111001111100111",
  "111001111001111",
  "101101111001001",
  "111100111001111",
  "111100111101111",
  "111001001001001",
  "111101111101111",
  "111101111001111"
};

int a[250][250];

string s;

int term(int &i);
int fact(int &i);

int exp(int &i) {
  int p = term(i);
  while(s[i]=='+' || s[i]=='-') {
    char c = s[i++];
    if (c == '+') {
      int a = term(i);
      p += a;
    }
    else p -= term(i);
  }
  return p;
}

int term(int &i) {
  int p = fact(i);
  while(s[i]=='*') {
    i++;
    p *= fact(i);
  }
  return p;
}

int fact(int &i) {
  if (s[i] == '(') {
    i++;
    int p = exp(i);
    assert(s[i++]==')');
    return p;
  } else {
    int num = 0;
    while(isdigit(s[i])) {
      num *= 10;
      num += s[i]-'0';
      i++;
    }
    return num;
  }
}

enum Type {EXPR, TERM, FACT};
int parse(Type t, int &i) {
  int p;
  if (t == EXPR) {
    p = parse(TERM, i);
    while(s[i]=='+' || s[i]=='-') {
      if (s[i++] == '+') p += term(i);
      else p -= term(i);
    }
  } else if (t == TERM) {
    p = fact(i);
    while(s[i]=='*') {
      i++;
      p *= fact(i);
    }
  } else if (t == FACT) {
    if (s[i]=='(') {
      i++;
      p = exp(i);
      assert(s[i++]==')');
    } else { 
      p = 0;
      while(isdigit(s[i])) {
        p *= 10;
        p += s[i]-'0';
        i++;
      }
    }
  }
  return p;
}

int main() {
  int n;
  while(cin >> n) {
    memset(a,0,sizeof(a));
    REP(i,n) {
      int x1,y1,x2,y2;
      cin >> x1 >> y1 >> x2 >> y2;
      if (x1 == x2) {
        if (y1>y2)swap(y1,y2);
        for (int y=y1; y<=y2; ++y) {
          a[y][x1] = 1;
        }
      } else {
        if (x1>x2)swap(x1,x2);
        for (int x=x1; x<=x2; ++x) {
          a[y1][x] = 1;
        }
      }
    }
    // REP(i,10) {
    //   REP(j,10) cout << a[i][j] << " ";
    //   cout << endl;
    // }
    s = "";
    const int dy[] = {-1,0,1,0};
    const int dx[] = {0,1,0,-1};

    int id = 2;
    REP(x,250) {
      REP(y,250) {
        if (a[y][x] == 1) {
          queue<pii> Q;
          Q.push(pii(y,x));
          a[y][x] = id;
          int y1,x1,y2,x2;
          y1=y2=y;
          x1=x2=x;
          while(!Q.empty()) {
            pii p = Q.front(); Q.pop();
            int cy = p.first;
            int cx = p.second;
            chmin(y1,cy);
            chmax(y2,cy);
            chmin(x1,cx);
            chmax(x2,cx);
            REP(i,4) {
              int yy=cy+dy[i];
              int xx=cx+dx[i];
              if (valid(yy,xx,250,250)&&a[yy][xx]==1) {
                a[yy][xx] = id;
                Q.push(pii(yy,xx));
              }
            }
          }
          int cw = x2-x1+1;
          int ch = y2-y1+1;
          // cout << cw << " " << ch << endl;
          if (cw == 1 && ch == 1) {
            s += "*";
          } else if (cw == 3 && ch == 1) {
            s += "-";
          } else if (cw == 3 && ch == 3) {
            s += "+";
          } else if (cw == 1 && ch == 5) {
            s += "1";
          } else {
            REP(i,10) {
              if (i==1) continue;

              bool ok = 1;

              REP(yy,5) {
                REP(xx,3) {
                  if (a[y1+yy][x1+xx] == id ^ t[i][yy*3+xx]=='1') {
                    ok = 0;
                  }
                }
              }
              if (ok) {
                s += '0' + i;
              }
            }
          }
          id++;
        }
      }
    }

    int i = 0;
    cout << exp(i) << endl;
  }
}


Measured memory_bytes: 1472