```ts
export function scanPairs(input: string): string[][] {
  if (typeof input !== 'string') throw new Error('Input must be a string');
  if (!input) return [];

  const parseOption = (segment: string): string[] => {
    if (typeof segment !== 'string') throw new Error('Segment must be a string');
    const [key, value] = segment.split('=').map((part, i) => {
      if (i === 0) {
        if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(part)) {
          throw new Error(`Invalid key: ${part}`);
        }
        return part;
      } else {
        const quotes = ['"', "'"];
        for (const quote of quotes) {
          if (value.startsWith(quote) && value.endsWith(quote)) {
            return value.slice(1, -1);
          }
        }
        return value;
      }
    });

    if (!key || !value) throw new Error('Invalid segment format');

    return [key, value];
  };

  const result: string[][] = [];
  let currentSegment = '';
  let inQuotes = false;

  for (const char of input) {
    if (char === ';') {
      if (inQuotes) {
        currentSegment += ';';
      } else {
        if (currentSegment.trim()) {
          result.push(parseOption(currentSegment));
        }
        currentSegment = '';
      }
    } else if (char === '"' || char === "'") {
      if (!inQuotes) inQuotes = true;
      else if (char === input[input.length - 1]) inQuotes = false;
      currentSegment += char;
    } else {
      currentSegment += char;
    }
  }

  if (currentSegment.trim()) result.push(parseOption(currentSegment));

  return result;
}
```