Finding Lonely Primes Lonely primes (as I call them) are primes, where given a number grid with width w ≥ 3, are primes which do not have any other primes adjacent to them orthogonally or diagonally.

For example, if we take this grid where w = 12 (primes highlighted in bold):

1   2   3   4   5   6   7   8   9   10  11  12
13  14  15  16  17  18  19  20  21  22  23...
 ...86  87  88  89  90  91  92  93  94  95  96
97  98  99  100 101 102 103 104 105 106 107 108
109 110 111 112 113 114 115 116 117 118 119 120

You can see that only the two primes 103 and 107 have no primes orthogonally or diagonally adjecant whatsoever. I've skipped over a section because there's no lonely primes there. (except 37, actually)

Your task is to, given two inputs w ≥ 3 and i ≥ 1, determine the first lonely prime in a number grid with width w, where said lonely prime must be greater than or equal to i. Inputs may be taken in any reasonable format (including taking them as strings). It is guaranteed there will be a lonely prime for width w.

The grid doesn't wrap around.

Examples:

w  i   output
11 5   11
12 104 107
12 157 157
9  1   151
12 12  37


As this is code-golf, shortest code wins!
C (gcc), 159 158 149 145 bytes

Saved a byte thanks to xanoetux; removing one newline character.
Saved nine thirteen bytes thanks to ceilingcat; golfing a break condition.


P(n,d,b){for(d=b=1&lt;n;n&gt;++d;)b*=n%d&gt;0;n=b;}F(w,i){w=P(i)&amp;!(P(i-w)|P(i+w)|i%w&gt;1&amp;(P(--i)|P(i-w)|P(i+w))|++i%w&gt;0&amp;(P(++i)|P(i-w)|P(i+w)))?i-1:F(w,i);}

Try it online!