#include #define int long long #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() using namespace std; templateistream&operator>>(istream&I,vector&v){for(auto&i:v)I>>i;return I;} templateostream&operator<<(ostream&O,vector&v){for(auto&i:v)O<>n>>m>>k>>p; n++,m++; vectorv(k); for(auto&[x,y,s]:v)cin>>x>>y>>s; vectorans; int mx=0; for(int b=0;b<1<tmp; vector>dp(n+1,vector(m+1,0)); for(int i=0;imx){ mx=dp[n-1][m-1]; ans=tmp; } } cout<>t; while(t--)AC::solve(); }