const array=[];

const treePush=(obj,searchNum,num)=>{  
  obj.childlen.forEach(e=>{
    treePush(e,searchNum,num)
  })  
}

const treeSearch=(obj,num)=>{
  var flag=false;
  obj.childlen.forEach(e=>{
    if(e.number == num){
      return e;
      flag=true;
    }
  })
  if(flag=false){
    obj.childlen.forEach(e=>{      
      treeSearch(e,num)
    })
  }
}


const treeCounter=(obj,counterNum)=>{
  if(obj){
    obj.counter+=counterNum
    obj.childlen.forEach(e=>{
      treeCounter(e,counterNum);
    })
  }  
}

const treeCount=(obj)=>{
  obj.childlen.forEach(e=>{
      array.push(e.counter);
      e.childlen.forEach(f=>{
        treeCount(e);
      })
  })
}

function Main(input) {
  input = input.split("\n");
  var a = input.slice(1,(input.length-1)/2+1)
  var b = input.slice((input.length-1)/2+2,input.length)
  a = a.map(e=>{
    return e.split(" ").map(f=>{
      return parseInt(f,10);    
    })        
  })
  b = b.map(e=>{
    return e.split(" ").map(f=>{
      return parseInt(f,10);
    })        
  })
  const tree = {number:1,childlen:[],counter:0}

  a.forEach(e=>{
    if(e[0]==1){
      tree.childlen.push(
        {number:e[1],childlen:[],counter:0}
      )
    }else{
      var flag=false;
      tree.childlen.forEach(f=>{
        if(f.number==e[0]){
          f.childlen.push({number:e[1],childlen:[],counter:0})          
          flag=true;
        }        
      })
      if(flag=false){
        tree.childlen.forEach(f=>{          
          treePush(f,e[0],e[1]);
        })
      }
    }
  })

  b.forEach(e=>{
    if(e[0]==1){
      treeCounter(tree,e[1])
    }else{
      treeCounter(treeSearch(tree,e[0]),e[1])
    }
  })

  array.push(tree.counter);
  treeCount(tree);  
  console.log(array);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
