#include <bits/stdc++.h>
#include <fstream>
#define INF 800000000000
#define MOD 100000007
#define MAXN 100005
#define ins insert
#define pb push_back
#define mp make_pair
#define sz size
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for(int i = a; i < b; ++i)
#define sd(n) scanf("%d",&n)
#define sll(n) scanf("%I64d",&n)
#define pdn(n) printf("%d\n",n)
#define plln(n) printf("%I64d\n",n)
#define pd(n) printf("%d ",n)
#define nl() printf("\n")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
namespace patch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
stm.str() ;
}
}
ll modpow(ll base, ll exponent, int modulus)
{
ll result = 1;
while (exponent > 0)
{
if (exponent % 2 == 1)
result = (result * base) % modulus;
exponent = exponent >> 1;
base = (base * base) % modulus;
}
return result;
}
ll gcd(ll u, ll v)
{
return (v != 0) ? gcd(v, u % v) : u;
}
int t, n, k, m, score[10001];
vvi ad(10001), del(10001);
multiset<int> mm;
ll mincost[10001], dp[10001][501];
/*ll solve(int idx, int rem) {
if(rem < 0)
return -50000000LL;
if(idx == 0)
return 0;
if(dp[idx][rem] != 800000000LL)
return dp[idx][rem];
return dp[idx][rem] = max(solve(idx-1, rem-mincost[idx]), solve(idx-1, rem)+(ll)score[idx]);
}*/
int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
sd(t);
while(t--) {
mm.clear();
rep(i, 0, 10001) {
rep(j, 0, 501)
dp[i][j] = 0;
ad[i].clear();
del[i].clear();
}
sd(n); sd(k); sd(m);
rep(i, 1, n+1)
scanf("%d", &score[i]);
rep(i, 0, m) {
int l, r, c;
sd(l); sd(r); sd(c);
ad[l].pb(c);
del[r].pb(c);
}
mm.ins(k+5);
rep(i, 1, n+1) {
rep(j, 0, ad[i].sz()) {
mm.ins(ad[i][j]);
}
mincost[i] = *mm.begin();
rep(j, 0, del[i].sz()) {
mm.erase(mm.find(del[i][j]));
}
}
//rep(i, 1, n+1)
// cout << mincost[i] << endl;
dp[0][0] = 0LL;
rep(i, 1, n+1)
dp[i][0] = dp[i-1][0] + (ll)score[i];
rep(i, 1, n+1) {
rep(j, 1, k+1) {
if(j >= mincost[i])
dp[i][j] = max(dp[i-1][j]+(ll)score[i], dp[i-1][j-mincost[i]]);
else
dp[i][j] = dp[i-1][j]+(ll)score[i];
}
}
printf("%lld\n", dp[n][k]);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxmc3RyZWFtPgojZGVmaW5lIElORiA4MDAwMDAwMDAwMDAKI2RlZmluZSBNT0QgMTAwMDAwMDA3CiNkZWZpbmUgTUFYTiAxMDAwMDUKI2RlZmluZSBpbnMgaW5zZXJ0CiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgc3ogc2l6ZQojZGVmaW5lIGFsbChhKSBhLmJlZ2luKCksIGEuZW5kKCkKI2RlZmluZSByZXAoaSwgYSwgYikgZm9yKGludCBpID0gYTsgaSA8IGI7ICsraSkKI2RlZmluZSBzZChuKSBzY2FuZigiJWQiLCZuKQojZGVmaW5lIHNsbChuKSBzY2FuZigiJUk2NGQiLCZuKQojZGVmaW5lIHBkbihuKSBwcmludGYoIiVkXG4iLG4pCiNkZWZpbmUgcGxsbihuKSBwcmludGYoIiVJNjRkXG4iLG4pCiNkZWZpbmUgcGQobikgcHJpbnRmKCIlZCAiLG4pCiNkZWZpbmUgbmwoKSBwcmludGYoIlxuIikKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHVuc2lnbmVkIGxvbmcgbG9uZyB1bGw7CnR5cGVkZWYgdmVjdG9yPGludD4gdmk7CnR5cGVkZWYgdmVjdG9yPGxsPiB2bDsKdHlwZWRlZi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0gODAwMDAwMDAwTEwpCiAgICAgICAgcmV0dXJuIGRwW2lkeF1bcmVtXTsKICAgIHJldHVybiBkcFtpZHhdW3JlbV0gPSBtYXgoc29sdmUoaWR4LTEsIHJlbS1taW5jb3N0W2lkeF0pLCBzb2x2ZShpZHgtMSwgcmVtKSsobGwpc2NvcmVbaWR4XSk7Cn0qLwoKaW50IG1haW4oKSB7CiAgICAvL2lvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICAvL2Npbi50aWUoMCk7CiAgICAvL2NvdXQudGllKDApOwogICAgc2QodCk7CiAgICB3aGlsZSh0LS0pIHsKICAgICAgICBtbS5jbGVhcigpOwogICAgICAgIHJlcChpLCAwLCAxMDAwMSkgewogICAgICAgICAgICByZXAoaiwgMCwgNTAxKQogICAgICAgICAgICAgICAgZHBbaV1bal0gPSAwOwogICAgICAgICAgICBhZFtpXS5jbGVhcigpOwogICAgICAgICAgICBkZWxbaV0uY2xlYXIoKTsgICAgCiAgICAgICAgfQogICAgICAgIHNkKG4pOyBzZChrKTsgc2QobSk7CiAgICAgICAgcmVwKGksIDEsIG4rMSkKICAgICAgICAgICAgc2NhbmYoIiVkIiwgJnNjb3JlW2ldKTsKICAgICAgICByZXAoaSwgMCwgbSkgewogICAgICAgICAgICBpbnQgbCwgciwgYzsKICAgICAgICAgICAgc2QobCk7IHNkKHIpOyBzZChjKTsKICAgICAgICAgICAgYWRbbF0ucGIoYyk7CiAgICAgICAgICAgIGRlbFtyXS5wYihjKTsKICAgICAgICB9CiAgICAgICAgbW0uaW5zKGsrNSk7CiAgICAgICAgcmVwKGksIDEsIG4rMSkgewogICAgICAgICAgICByZXAoaiwgMCwgYWRbaV0uc3ooKSkgewogICAgICAgICAgICAgICAgbW0uaW5zKGFkW2ldW2pdKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBtaW5jb3N0W2ldID0gKm1tLmJlZ2luKCk7CiAgICAgICAgICAgIHJlcChqLCAwLCBkZWxbaV0uc3ooKSkgewogICAgICAgICAgICAgICAgbW0uZXJhc2UobW0uZmluZChkZWxbaV1bal0pKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvL3JlcChpLCAxLCBuKzEpCiAgICAgICAgLy8gICAgY291dCA8PCBtaW5jb3N0W2ldIDw8IGVuZGw7CiAgICAgICAgZHBbMF1bMF0gPSAwTEw7CiAgICAgICAgcmVwKGksIDEsIG4rMSkKICAgICAgICAgICAgZHBbaV1bMF0gPSBkcFtpLTFdWzBdICsgKGxsKXNjb3JlW2ldOwogICAgICAgIHJlcChpLCAxLCBuKzEpIHsKICAgICAgICAgICAgcmVwKGosIDEsIGsrMSkgewogICAgICAgICAgICAgICAgaWYoaiA+PSBtaW5jb3N0W2ldKQogICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gbWF4KGRwW2ktMV1bal0rKGxsKXNjb3JlW2ldLCBkcFtpLTFdW2otbWluY29zdFtpXV0pOwogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gZHBbaS0xXVtqXSsobGwpc2NvcmVbaV07CiAgICAgICAgICAgIH0KICAgICAgICB9ICAgICAgCiAgICAgICAgcHJpbnRmKCIlbGxkXG4iLCBkcFtuXVtrXSk7ICAKICAgIH0KICAgIHJldHVybiAwOwp9