I have a 2D tensor and I have the following problem:

```
a=tensor([[1296, 1295, 1292, 4, 1311, 4, 1293, 2],
[1297, 1295, 1292, 1404, 1294, 4, 1293, 2]]
```

I need to mask all values greater than 1292, also I want to mask values in sorted order by incrementing values. What I want is:

```
tensor([[3, 2, 1292, 4, 5, 4, 1, 2],
[4, 3, 1292, 5, 2, 4, 1, 2]]
```

How can I do this?