BDLORD is correct. Since you will be domestic after reaching GRU, Immigration and Customs will be done there. Here is a map of GRU from the *A website:
http://www.staralliance.com/assets/i..._map_large.gif
Will your TAM flight be out of GRU or CGH (the domestic airport)? If CGH, I believe TAM operates a shuttle bus between the two airports.