# Ruby, <s>113</s> <s>112</s> <s>105</s> <s>98</s> <s>97</s> <s>95</s> 87 bytes

<!--language-all:lang-ruby-->

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to [manatwork][1], another byte thanks to [Martin Büttner][2], and 8 more bytes thanks to [cia_rana][3].

    ->n,f,t,d{z=0;s='';n.chars{|i|z=z*f+d.index(i)};(s=d[z%t]+s;z/=t)while z>0;s[0]?s:d[0]}

Ungolfed:

    def a(n,f,t,d)
      z=0
      s=''
      n.chars do |i|
        z = z*f + d.index(i)
      end
      while z>0 
        s = d[z%t] + s
        z /= t
      end
      if s[0]   # if n not zero
        return s
      else
        return d[0]
      end
    end


  [1]: https://codegolf.stackexchange.com/users/4198/manatwork
  [2]: https://codegolf.stackexchange.com/users/8478/martin-b%c3%bcttner
  [3]: https://codegolf.stackexchange.com/users/59228/cia-rana