#!/usr/bin/env python3

import sys
import os
from subprocess import check_output

def main(args):
    if not args:
        exit(1)
    for arg in args:
        path = check_output(['which', arg]).decode('utf8').rstrip('\n')
        while os.path.islink(path):
            path = os.readlink(path)
        print(path)

if __name__ == '__main__':
    main(sys.argv[1:])