#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MN = 1005;
int n, k, bt[MN], dep[MN][MN], dp[MN];
int rec(int cur)
{
int& ret = dp[cur];
if(ret) return ret;
ret = bt[cur];
for(int prev = 1; prev <= n; ++prev){
if(dep[prev][cur]){
ret = max(ret, rec(prev) + bt[cur]);
}
}
return ret;
}
int main()
{
int t;
cin >> t;
while(t--){
cin >> n >> k;
for(int i = 1; i <= n; ++i){
dp[i] = 0;
for(int j = 1; j <= n; ++j){
dep[i][j] = 0;
}
}
for(int i = 1; i <= n; ++i){
cin >> bt[i];
}
for(int i = 0; i < k; ++i){
int a, b;
cin >> a >> b;
dep[a][b] = 1;
}
int target;
cin >> target;
cout << rec(target) << '\n';
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNTiA9IDEwMDU7CmludCBuLCBrLCBidFtNTl0sIGRlcFtNTl1bTU5dLCBkcFtNTl07CgppbnQgcmVjKGludCBjdXIpCnsKCWludCYgcmV0ID0gZHBbY3VyXTsKCWlmKHJldCkgcmV0dXJuIHJldDsKCXJldCA9IGJ0W2N1cl07Cglmb3IoaW50IHByZXYgPSAxOyBwcmV2IDw9IG47ICsrcHJldil7CgkJaWYoZGVwW3ByZXZdW2N1cl0pewoJCQlyZXQgPSBtYXgocmV0LCByZWMocHJldikgKyBidFtjdXJdKTsKCQl9Cgl9CglyZXR1cm4gcmV0Owp9CgppbnQgbWFpbigpCnsKCWludCB0OwoJY2luID4+IHQ7Cgl3aGlsZSh0LS0pewoJCWNpbiA+PiBuID4+IGs7CgkJZm9yKGludCBpID0gMTsgaSA8PSBuOyArK2kpewoJCQlkcFtpXSA9IDA7CgkJCWZvcihpbnQgaiA9IDE7IGogPD0gbjsgKytqKXsKCQkJCWRlcFtpXVtqXSA9IDA7CgkJCX0KCQl9CgoJCWZvcihpbnQgaSA9IDE7IGkgPD0gbjsgKytpKXsKCQkJY2luID4+IGJ0W2ldOwoJCX0KCgkJZm9yKGludCBpID0gMDsgaSA8IGs7ICsraSl7CgkJCWludCBhLCBiOwoJCQljaW4gPj4gYSA+PiBiOwoJCQlkZXBbYV1bYl0gPSAxOwoJCX0KCgkJaW50IHRhcmdldDsKCQljaW4gPj4gdGFyZ2V0OwoJCWNvdXQgPDwgcmVjKHRhcmdldCkgPDwgJ1xuJzsKCX0KfQ==