Your best bet is to use expect (expect.sourceforge.net).
Expect is a program specifically designed for this type of interaction.
If you run autoexpect and enter all the necessary commands and info to change one password, it will generate a script which you can edit and use for the general case by putting in variables in the appropriate places - e.g. for usernames and passwords.
here is how i would do it:
% mkdir workspace
% cd workspace
% autoexpect ssh user@hostname
autoexpect will start the ssh session and record all input/output to script.exp. Do all the steps to change password here. Then exit the ssh session. This will create script.exp which you can edit.
NB. you don't need or want the ssh -t option with expect.
Then call your expect script from within your loop, passing it the hostname, username, etc.
Hope this helps.