I have no access to the files on the onedrive server so I cannot test with them.
With a simple test file (with layers only for »a« through »f«) I was able to use the Script below to get an Array of Arrays (containing the Layer’s name, the index [which can be used to address/select the layer], the bounds [which can be used to calculate the necessary offsets]) in which the layers starting with the intended letter are being »rotated« (see the multiple »e«s for example).


// 2023, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
////////////////////////////////////
var theString = "badebefefe";
var theLayers = collectLayersBounds ();
theLayers.sort();
var theRegExp = /^\D\d$/i;
// create arrays sorted by initial letter;
var theArrays = new Array;
for (var m = 0; m < theLayers.length; m++) {
var thisOne = theLayers[m];
var theCheck = false;
if (thisOne[0].match(theRegExp) != null) {
var theLetter = String(thisOne[0].match(/^\D/i));
for (var n = 0; n < theArrays.length; n++) {
if (theArrays[n][0][0][0] == theLetter) {
theArrays[n].push(thisOne);
var theCheck = true
}
};
if (theCheck != true) {theArrays.push([thisOne])};
}
};
// check string against array;
var theResult = new Array;
for (var o = 0; o < theString.length; o++) {
var thisOne = theString[o];
for (var p = 0; p < theArrays.length; p++) {
if (theArrays[p][0][0][0].match(new RegExp (thisOne, "i")) != null) {
theResult.push (theArrays[p][0])
theArrays[p].push(theArrays[p].splice(0,1));
}
};
};
alert (theResult.join("\n"));
////////////////////////////////////
app.preferences.rulerUnits = originalRulerUnits;
};
////// collect layers //////
function collectLayersBounds () {
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
theLayers.push([theName, theID, theseBounds])
};
}
catch (e) {};
};
return theLayers
};