#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define rep(i,j,k) for (int (i)=(j);(i)<=(k);++(i))
using namespace std;
typedef long long ll;
const int N=(int)1e5;
const ll inf=0x7f7f7f7f7f7f7f7fll;
int n,Q,mm,a[N+10],d[N+10],son[N+10],size[N+10],ed[N*2+10],nxt[N*2+10],cost[N*2+10];
inline void addedge(int x,int y,int z){
nxt[++mm]=son[x]; son[x]=mm; ed[mm]=y; cost[mm]=z;
nxt[++mm]=son[y]; son[y]=mm; ed[mm]=x; cost[mm]=z;
}
inline int getint(){
int x=0;
bool flag=false;
char ch=getchar();
while (!(ch>='0' && ch<='9' || ch=='-')) ch=getchar();
if (ch=='-') flag=true,ch=getchar();
while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return flag?-x:x;
}
namespace baoli1{
const int N=(int)5e3;
ll f[N+10];
void dfs1(int x,int pre){
size[x]=a[x];
for (int i=son[x];i;i=nxt[i])
if (ed[i]!=pre){
d[ed[i]]=d[x]+cost[i];
dfs1(ed[i],x);
size[x]+=size[ed[i]];
}
}
void dfs2(int x,int pre){
for (int i=son[x];i;i=nxt[i])
if (ed[i]!=pre){
f[ed[i]]=f[x]+(ll)(size[1]-2*size[ed[i]])*cost[i];
dfs2(ed[i],x);
}
}
void solve(){
while (Q--){
int u,e;
scanf("%d%d",&u,&e);
a[u]+=e;
dfs1(1,0);
f[1]=0;
rep(i,2,n) f[1]+=(ll)d[i]*a[i];
dfs2(1,0);
ll ans=inf;
rep(i,1,n) ans=min(ans,f[i]);
printf("%lld\n",ans);
}
exit(0);
}
}
namespace baoli2{
const ll inf=0x7f7f7f7f7f7f7f7fll;
ll f;
bool vis[N+10];
int cnt,root=1,total,d[N+10],fa[N+10],id[N+10],dis[N+10],deep[N+10],head[N+10],heavy[N+10],pedge[N+10],seg[N*4+10];
inline void update(int k){
seg[k]=seg[k*2]+seg[k*2+1];
}
void modify(int k,int lc,int rc,int p,int d){
if (lc==rc){
seg[k]+=d;
return;
}
int mid=lc+rc>>1;
if (p<=mid) modify(k*2,lc,mid,p,d);
else modify(k*2+1,mid+1,rc,p,d);
update(k);
}
int query(int k,int lc,int rc,int l,int r){
if (l==lc && r==rc) return seg[k];
int mid=lc+rc>>1;
if (r<=mid) return query(k*2,lc,mid,l,r);
if (l>mid) return query(k*2+1,mid+1,rc,l,r);
return query(k*2,lc,mid,l,mid)+query(k*2+1,mid+1,rc,mid+1,r);
}
void dfs(int x,int pre){
size[x]=1;
for (int i=son[x];i;i=nxt[i])
if (ed[i]!=pre){
fa[ed[i]]=x;
pedge[ed[i]]=cost[i];
deep[ed[i]]=deep[x]+1;
dis[ed[i]]=dis[x]+cost[i];
dfs(ed[i],x);
size[x]+=size[ed[i]];
if (size[ed[i]]>size[heavy[x]]) heavy[x]=ed[i];
}
}
void dfs2(int x){
id[x]=++cnt;
vis[x]=true;
if (!head[x]) head[x]=x;
if (heavy[x]){
head[heavy[x]]=head[x];
dfs2(heavy[x]);
}
for (int i=son[x];i;i=nxt[i])
if (!vis[ed[i]]) dfs2(ed[i]);
}
inline ll calc(int x){
int t=fa[root]==x?total-query(1,1,n,id[root],id[root]+size[root]-1):query(1,1,n,id[x],id[x]+size[x]-1),p=fa[root]==x?pedge[root]:pedge[x];
return f-(ll)t*p+(ll)(total-t)*p;
}
void move(int x){
ll minval=inf;
int id=0;
for (int i=son[x];i;i=nxt[i]){
ll t=calc(ed[i]);
if (t<minval){
minval=t;
id=ed[i];
}
}
if (minval<f){
root=id;
f=minval;
move(root);
}
}
inline int getlca(int x,int y){
while (head[x]!=head[y])
if (deep[head[x]]>deep[head[y]]) x=fa[head[x]]; else y=fa[head[y]];
return deep[x]<deep[y]?x:y;
}
inline int dist(int x,int y){
return dis[x]+dis[y]-2*dis[getlca(x,y)];
}
inline void update(int x,int y){
total+=y;
modify(1,1,n,id[x],y);
}
void solve(){
dfs(1,0);
dfs2(1);
while (Q--){
int u=getint(),e=getint();
f+=(ll)e*dist(u,root);
update(u,e);
move(root);
printf("%lld\n",f);
}
exit(0);
}
}
int main(){
n=getint(); Q=getint();
rep(i,2,n){
int x=getint(),y=getint(),z=getint();
addedge(x,y,z);
}
if (n<=5000 && Q<=2000) baoli1::solve();
baoli2::solve();
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxhbGdvcml0aG0+CgojZGVmaW5lIHJlcChpLGosaykgZm9yIChpbnQgKGkpPShqKTsoaSk8PShrKTsrKyhpKSkKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmNvbnN0IGludCBOPShpbnQpMWU1Owpjb25zdCBsbCBpbmY9MHg3ZjdmN2Y3ZjdmN2Y3ZjdmbGw7CgppbnQgbixRLG1tLGFbTisxMF0sZFtOKzEwXSxzb25bTisxMF0sc2l6ZVtOKzEwXSxlZFtOKjIrMTBdLG54dFtOKjIrMTBdLGNvc3RbTioyKzEwXTsKCmlubGluZSB2b2lkIGFkZGVkZ2UoaW50IHgsaW50IHksaW50IHopewoJbnh0WysrbW1dPXNvblt4XTsgc29uW3hdPW1tOyBlZFttbV09eTsgY29zdFttbV09ejsKCW54dFsrK21tXT1zb25beV07IHNvblt5XT1tbTsgZWRbbW1dPXg7IGNvc3RbbW1dPXo7Cn0KCmlubGluZSBpbnQgZ2V0aW50KCl7CglpbnQgeD0wOwoJYm9vbCBmbGFnPWZhbHNlOwoJY2hhciBjaD1nZXRjaGFyKCk7Cgl3aGlsZSAoIShjaD49JzAnICYmIGNoPD0nOScgfHwgY2g9PSctJykpIGNoPWdldGNoYXIoKTsKCWlmIChjaD09Jy0nKSBmbGFnPXRydWUsY2g9Z2V0Y2hhcigpOwoJd2hpbGUgKGNoPj0nMCcgJiYgY2g8PSc5JykgeD14KjEwK2NoLScwJyxjaD1nZXRjaGFyKCk7CglyZXR1cm4gZmxhZz8teDp4Owp9CgpuYW1lc3BhY2UgYmFvbGkxewoJY29uc3Qga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