The field $F = GF(3^{151})$ is a 151-dimensional vector space over $GF(3)$, so its elements can be viewed as vectors of length 151 with entries in ${0,1,2}$, or as natural numbers $< 3^{151}$ written in base 3. To do the conversion in SageMath, you can do:
B = F(B.digits(3))