#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

#ifdef LOCAL
#include "local.h"
#endif

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

template <typename T, typename U> void upmin(T& a, const U& b) { a = min<T>(a, b); }
template <typename T, typename U> void upmax(T& a, const U& b) { a = max<T>(a, b); }
template <typename T> void uniq(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

typedef long long ll;
typedef pair<int, int> pint;

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

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)


const char* g_zero[] = { 
    "@@@",
    "@.@",
    "@.@",
    "@.@",
    "@@@",
};
const char* g_one[] = { 
    "..@",
    "..@",
    "..@",
    "..@",
    "..@",
};
const char* g_two[] = { 
    "@@@",
    "..@",
    "@@@",
    "@..",
    "@@@",
};
const char* g_three[] = { 
    "@@@",
    "..@",
    "@@@",
    "..@",
    "@@@",
};
const char* g_four[] = { 
    "@.@",
    "@.@",
    "@@@",
    "..@",
    "..@",
};
const char* g_five[] = { 
    "@@@",
    "@..",
    "@@@",
    "..@",
    "@@@",
};
const char* g_six[] = { 
    "@@@",
    "@..",
    "@@@",
    "@.@",
    "@@@",
};
const char* g_seven[] = { 
    "@@@",
    "..@",
    "..@",
    "..@",
    "..@",
};
const char* g_eight[] = { 
    "@@@",
    "@.@",
    "@@@",
    "@.@",
    "@@@",
};
const char* g_nine[] = { 
    "@@@",
    "@.@",
    "@@@",
    "..@",
    "@@@",
};
const char* g_plus[] = { 
    "...",
    ".@.",
    "@@@",
    ".@.",
    "...",
};
const char* g_minus[] = { 
    "...",
    "...",
    "@@@",
    "...",
    "...",
};
const char* g_product[] = {
    "...",
    "...",
    ".@.",
    "...",
    "...",
};
set<pint> normalize(const set<pint>& s)
{
    set<pint> res;
    pint o = *s.begin();
    foreach(it, s)
    {
        pint t = *it;
        t.first -= o.first;
        t.second -= o.second;
        res.insert(t);
    }
    return res;
}
set<pint> convert(const char** g)
{
    set<pint> s;
    rep(y, 5) rep(x, 3)
        if (g[y][x] == '@')
            s.insert(pint(x, y));
    return normalize(s);
}


char c[256][256];
void land(int x, int y, set<pint>& s)
{
    if (c[y][x] == '.')
        return;
    c[y][x] = '.';
    s.insert(pint(x, y));
    rep(dir, 4)
        land(x + dx[dir], y + dy[dir], s);
}

typedef pair<int, int> result;
#define value first
#define p second

result equation(const string &s, int p = 0);
result factor(const string &s, int p = 0);
result term(const string &s, int p = 0);

result equation(const string &s, int p) {
  result r = factor(s, p);
  while (s[r.p] == '+' || s[r.p] == '-') {
    result r_ = factor(s, r.p+1);
    if (s[r.p] == '+')
        r.value += r_.value;
    else
        r.value -= r_.value;

    r.p      = r_.p;
  }
  return r;
}
result factor(const string &s, int p) {
  result r = term(s, p);
  while (s[r.p] == '*') {
    result r_ = term(s, r.p+1);
    r.value *= r_.value;
    r.p      = r_.p;
  }
  return r;
}
result term(const string &s, int p) {
  if (s[p] == '(') {
    result r = equation(s, p+1);
    r.p += 1; // skip ')'
    return r;
  } else {
    int value = 0;
    while (isdigit(s[p]))
      value = value * 10 + (s[p++] - '0');
    return result(value, p);
  }
}

int eval(string e)
{
    return equation(e).value;
}

int main()
{
    map<set<pint>, char> char_table;
#define add(g, c) char_table[convert(g)] = c
    add(g_zero, '0');
    add(g_one, '1');
    add(g_two, '2');
    add(g_three, '3');
    add(g_four, '4');
    add(g_five, '5');
    add(g_six, '6');
    add(g_seven, '7');
    add(g_eight, '8');
    add(g_nine, '9');
    add(g_plus, '+');
    add(g_minus, '-');
    add(g_product, '*');

    clr(c, '.');
    int n;
    cin >> n;
    rep(i, n)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        ++x1, ++x2, ++y1, ++y2;
        if (x1 == x2)
        {
            if (y1 > y2)
                swap(y1, y2);
            for (int y = y1; y <= y2; ++y)
                c[y][x1] = '@';
        }
        else
        {
            if (x1 > x2)
                swap(x1, x2);
            for (int x = x1; x <= x2; ++x)
                c[y1][x] = '@';
        }
    }


    string expr;
    rep(x, 250)
    {
        rep(y, 250)
        {
            if (c[y][x] == '@')
            {
                set<pint> pos;
                land(x, y, pos);
                expr += char_table[normalize(pos)];
            }
        }
    }
    cout << eval(expr) << endl;
}


Measured memory_bytes: 1288