import string


def format_seconds(seconds):
    """
    Convert seconds to hours, minutes and seconds.
    """
    time_str = ''
    for base, char in (
            (60, 's'),
            (60, 'm'),
            (24, 'h')
    ):
        seconds, remainder = divmod(seconds, base)
        if seconds == 0:
            return '{:d}{}{}'.format(remainder, char, time_str)
        if remainder != 0:
            time_str = '{:02d}{}{}'.format(remainder, char, time_str)
    return '{:d}d{}'.format(seconds, string)