#include <bits/stdc++.h>

#ifdef HOME
#define db(x) cerr << #x << " = " << x << endl
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define dbv(a) cerr << #a << " = "; for (auto xxx: a) cerr << xxx  << " "; cerr << endl
#else
#define db(x) ;
#define db3(x, y, z) ;
#define db2(x, y) ;
#define dbv(a) ;
#endif

using namespace std;
typedef long long ll;
typedef long double dbl;


const int INF = 1.01e9;
const int MOD = (int)1e9 + 7;

struct Item {
    int x, y;
    ll val;
};

struct Cond {
    char type;
    int a, b;

    bool cover(Item it) {
        if (type == 'L') {
            return it.x <= a;
        }
        if (type == 'R') {
            return it.x >= a;
        }
        if (type == 'D') {
            return it.y <= a;
        }
        if (type == 'U') {
            return it.y >= a;
        }
        assert(0);
    }
};

ll slow(vector<Item> a, vector<Cond> b) {
    int n = a.size(), m = b.size();
    ll ans = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
        vector<int> cnt(m);
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            if (!(mask & (1 << i))) continue;
            sum += a[i].val;
            for (int j = 0; j < m; j++) {
                if (b[j].cover(a[i])) {
                    cnt[j]++;
                }
            }
        }
        bool bad = 0;
        for (int i = 0; i < m; i++) {
            if (cnt[i] > b[i].b) {
                bad = 1;
            }
        }
        if (bad) continue;
        ans = max(ans, sum);
    }
    return ans;
}


bool eq(dbl a, dbl b) {
    return fabs(a - b) < 1e-9;
}

bool ls(dbl a, dbl b) {
    return !eq(a, b) && a < b;
}

vector<dbl> simplex(vector<vector<dbl> > a) {
    int n = a.size() - 1;
    int m = a[0].size() - 1;
    vector<int> left(n + 1), up(m + 1);
    iota(up.begin(), up.end(), 0);
    iota(left.begin(), left.end(), m);
    auto pivot = [&](int x, int y) {
        swap(left[x], up[y]);
        dbl k = a[x][y];
        a[x][y] = 1;
        vector<int> vct;
        for (int j = 0; j <= m; j++) {
            a[x][j] /= k;
            if (!eq(a[x][j], 0)) vct.push_back(j);
        }
        for (int i = 0; i <= n; i++) {
            if (eq(a[i][y], 0) || i == x) continue;
            k = a[i][y];
            a[i][y] = 0;
            for (int j : vct) a[i][j] -= k * a[x][j];
        }
    };
    while (1) {
        int x = -1;
        for (int i = 1; i <= n; i++) if (ls(a[i][0], 0) && (x == -1 || a[i][0] < a[x][0])) x = i;
        if (x == -1) break;
        int y = -1;
        for (int j = 1; j <= m; j++) if (ls(a[x][j], 0) && (y == -1 || a[x][j] < a[x][y])) y = j;
        if (y == -1) return vector<dbl>(m + 1, 0);
        pivot(x, y);
    }
    while (1) {
        int y = -1;
        for (int j = 1; j <= m; j++) if (ls(0, a[0][j]) && (y == -1 || a[0][j] > a[0][y])) y = j;
        if (y == -1) break;
        int x = -1;
        for (int i = 1; i <= n; i++) if (ls(0, a[i][y]) && (x == -1 || a[i][0] / a[i][y] < a[x][0] / a[x][y])) x = i;
        if (x == -1) assert(0); // unbounded
        pivot(x, y);
    }
    vector<dbl> ans(m + 1);
    for (int i = 1; i <= n; i++) if (left[i] <= m) ans[left[i]] = a[i][0];
    ans[0] = -a[0][0];
    return ans;
}
// j=1..m: x[j]>=0
// i=1..n: sum(j=1..m) A[i][j]*x[j] <= A[i][0]
// max sum(j=1..m) A[0][j]*x[j]
// res[0] is answer
// res[1..m] is certificate

ll fast(vector<Item> a, vector<Cond> b) {
    int n = a.size(), m = b.size();
    vector<vector<dbl>> c(m + 1, vector<dbl>(n + 1));
    for (int i = 0; i < n; i++) {
        c[0][1 + i] = a[i].val;
    }
    for (int i = 0; i < m; i++) {
        c[1 + i][0] = b[i].b;
        for (int j = 0; j < n; j++) {
            if (b[i].cover(a[j])) {
                c[1 + i][1 + j] = 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        vector<dbl> cur(n + 1);
        cur[0] = 1;
        cur[1 + i] = 1;
        c.push_back(cur);
    }
    ll res = 0;
    for (int cnt = 1; cnt <= n; cnt++) {
        auto cc = c;
        vector<dbl> cur(n + 1, 1);
        cur[0] = cnt;
        cc.push_back(cur);
        for (auto &x : cur) x *= -1;
        cc.push_back(cur);
        res = max(res, (ll)round(simplex(cc)[0]));
    }
    return res;
}

void stress() {
    for (int it =0;; it++) {
        mt19937_64 rnd(it);
        db(it);


        int n = rnd() % 10 + 1;
        vector<Item> a(n);
        for (int i =0 ; i < n; i++) {
            a[i].x = rnd() % 100;
            a[i].y = rnd() % 100;
            a[i].val = rnd() % (ll)1e15;
        }
        int m = rnd() % 10 + 1;
        vector<Cond> b(m);
        for (int i = 0; i < m; i++) {
            b[i].a = rnd() % 100;
            b[i].b = rnd() % (n + 1);
            b[i].type = "ULDR"[rnd() % 4];
        }

        auto ans1 = fast(a, b);
        auto ans2 = slow(a, b);
        if (ans1 != ans2) {
            cout << ans1 << " instead of " << ans2 << endl;
            exit(0);
        }
    }
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif
//    stress();

    int n;
    while (scanf("%d", &n) == 1) {
        vector<Item> a(n);
        for (int i = 0; i < n; i++) {
            scanf("%d%d%lld", &a[i].x, &a[i].y, &a[i].val);
        }
        int m;
        scanf("%d", &m);
        vector<Cond> b(m);
        for (int i = 0; i < m; i++) {
            scanf(" %c%d%d", &b[i].type, &b[i].a, &b[i].b);
        }

//        printf("%lld\n", slow(a, b));
        printf("%lld\n", fast(a, b));
    }

#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 1368