Implement an algorithm to recursively merge two nested dictionaries, resolving conflicts based on a specified strategy.
Implement merge_nested_dicts(first, second, strategy). Return a new dictionary without modifying either input. When both values for a key are dictionaries, merge them recursively. For non-dictionary conflicts, overwrite uses the value from second, while preserve keeps the value from first.
Inputs contain JSON-compatible values and have no cyclic references.
def merge_nested_dicts(first, second, strategy):