d = defaultdict(lambda : defaultdict(lambda : defaultdict(list)))
for key1, key2, key3, value in l:
    d[key1][key2][key3].append(value)
print(json.dumps(d, indent=4))
list of tuples to dictionary of dictionaries