<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def handle_wikidata_errors(data, query):
 """ Raises LookupError if wikidata error found """

    entities = data.get('entities')

    if not entities:
        raise LookupError(query)
    elif '-1' in entities:
        raise LookupError(query)
    else:
        item = list(entities.values())[0]
        if 'missing' in item:
            errmsg = "wikidata item %s has been deleted" % item['id']
            raise LookupError(errmsg)