a=" 一二三四五六七八九十百千".split(//u);$<.each{|l|v=0;l.chomp.gsub(/([一二三四五六七八九])?([千百十])?/u){v+=(a.index($1)||1)*10**($2?a.index($2)-9:0)};p v-1}