def METHOD_NAME(nm, row_nm, n=3):
    instances = []
    for i in range(n):
        inp = 'INP' if i == 0 else f'X{i}'
        out = 'OUT' if i == n - 1 else f'X{i+1}'
        instance = {
            'instance_name': f'U{i}',
            'abstract_template_name': row_nm,
            'fa_map': [{'formal': 'INP', 'actual': inp},
                       {'formal': 'OUT', 'actual': out}]
        }
        instances.append(instance)
    topmodule = {
        'name': nm,
        'parameters': ["INP", "OUT"],
        'instances': instances,
        'constraints': [
            {
                'constraint': 'Order',
                'direction': 'top_to_bottom',
                'instances': [f'U{i}' for i in range(n)],
                'abut': False
            }
        ]
    }
    topmodule['constraints'].append(
        {
            'constraint': 'SameTemplate',
            'instances': [f'U{i}' for i in range(n)]
        }
    )
    return topmodule