Dollar gains in first quarter as Middle East tensions boost safe-haven demand