Java | JavaScript | TypeScript | C++ | C# | Kotlin | Go Solution.
```Java []
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution {

    private static final int VALUE_OCCURS_ONLY_ONCE = -1;

    public List<Integer> solveQueries(int[] input, int[] queries) {
        return createListForMinCircularDistancePerValue(input, queries);
    }

    private List<Integer> createListForMinCircularDistancePerValue(int[] input, int[] queries) {
        List<Integer> minCircularDistancePerValue = new ArrayList<>();
        Map<Integer, List<Integer>> valueToIndexes = createMapValueToIndexes(input);

        for (int query : queries) {
            int index = query;
            int value = input[index];
            int indexInListOfIndexes = Collections.binarySearch(valueToIndexes.get(value), index);

            int minCircularDistance = getMinCircularDistance(valueToIndexes.get(value), indexInListOfIndexes, input.length);
            minCircularDistancePerValue.add(minCircularDistance);
        }
        return minCircularDistancePerValue;
    }

    private Map<Integer, List<Integer>> createMapValueToIndexes(int[] input) {
        Map<Integer, List<Integer>> valueToIndexes = new HashMap<>();
        for (int i = 0; i < input.length; ++i) {
            valueToIndexes.computeIfAbsent(input[i], indexes -> new ArrayList<>()).add(i);
        }
        return valueToIndexes;
    }

    private int getCircularDistanceFromPreviousIndex(List<Integer> indexes, int index, int sizeInput) {
        if (index > 0) {
            return indexes.get(index) - indexes.get(index - 1);
        }
        return sizeInput - indexes.get(indexes.size() - 1) + indexes.get(index);
    }

    private int getCircularDistanceFromFollowingIndex(List<Integer> indexes, int index, int sizeInput) {
        if (index + 1 < indexes.size()) {
            return indexes.get(index + 1) - indexes.get(index);
        }
        return sizeInput - indexes.get(index) + indexes.get(0);
    }

    private int getMinCircularDistance(List<Integer> indexes, int index, int sizeInput) {
        if (indexes.size() == 1) {
            return VALUE_OCCURS_ONLY_ONCE;
        }
        int previousDistance = getCircularDistanceFromPreviousIndex(indexes, index, sizeInput);
        int followingDistance = getCircularDistanceFromFollowingIndex(indexes, index, sizeInput);
        return Math.min(previousDistance, followingDistance);
    }
}
```
```JavaScript []
/**
 * @param {number[]} input
 * @param {number[]} queries
 * @return {number[]}
 */
var solveQueries = function (input, queries) {
    this.VALUE_OCCURS_ONLY_ONCE = -1;
    return createListForMinCircularDistancePerValue(input, queries);
};

/**
 * @param {number[]} input
 * @param {number[]} queries
 * @return {number[]}
 */
function createListForMinCircularDistancePerValue(input, queries) {
    const minCircularDistancePerValue = new Array();
    const valueToIndexes = createMapValueToIndexes(input);

    for (let query of queries) {
        const index = query;
        const value = input[index];
        const indexInListOfIndexes = binarySearch(valueToIndexes.get(value), index);

        const minCircularDistance = getMinCircularDistance(valueToIndexes.get(value), indexInListOfIndexes, input.length);
        minCircularDistancePerValue.push(minCircularDistance);
    }
    return minCircularDistancePerValue;
}

/**
 * @param {number[]} input
 * @return {Map<number, number[]>}
 */
function createMapValueToIndexes(input) {
    const valueToIndexes = new Map();
    for (let i = 0; i < input.length; ++i) {
        if (!valueToIndexes.has(input[i])) {
            valueToIndexes.set(input[i], new Array());
        }
        valueToIndexes.get(input[i]).push(i);
    }
    return valueToIndexes;
}

/**
 * @param {number[]} indexes
 * @param {number} index
 * @param {number} sizeInput
 * @return {number}
 */
function getCircularDistanceFromPreviousIndex(indexes, index, sizeInput) {
    if (index > 0) {
        return indexes[index] - indexes[index - 1];
    }
    return sizeInput - indexes[indexes.length - 1] + indexes[index];
}

/**
 * @param {number[]} indexes
 * @param {number} index
 * @param {number} sizeInput
 * @return {number}
 */
function getCircularDistanceFromFollowingIndex(indexes, index, sizeInput) {
    if (index + 1 < indexes.length) {
        return indexes[index + 1] - indexes[index];
    }
    return sizeInput - indexes[index] + indexes[0];
}

/**
 * @param {number[]} indexes
 * @param {number} index
 * @param {number} sizeInput
 * @return {number}
 */
function getMinCircularDistance(indexes, index, sizeInput) {
    if (indexes.length === 1) {
        return this.VALUE_OCCURS_ONLY_ONCE;
    }
    const previousDistance = getCircularDistanceFromPreviousIndex(indexes, index, sizeInput);
    const followingDistance = getCircularDistanceFromFollowingIndex(indexes, index, sizeInput);
    return Math.min(previousDistance, followingDistance);
}

/**
 * @param {number[]} indexes
 * @param {number} index
 * @return {number}
 */
function binarySearch(indexes, index) {
    let left = 0;
    let right = indexes.length - 1;
    const NOT_FOUND = -1;

    while (left <= right) {
        let mid = left + Math.floor((right - left) / 2);
        if (indexes[mid] === index) {
            return mid;
        }
        if (indexes[mid] < index) {
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }
    return NOT_FOUND;
}
```
```TypeScript []
function solveQueries(input: number[], queries: number[]): number[] {
    this.VALUE_OCCURS_ONLY_ONCE = -1;
    return createListForMinCircularDistancePerValue(input, queries);
};

function createListForMinCircularDistancePerValue(input: number[], queries: number[]): number[] {
    const minCircularDistancePerValue = new Array();
    const valueToIndexes = createMapValueToIndexes(input);

    for (let query of queries) {
        const index = query;
        const value = input[index];
        const indexInListOfIndexes = binarySearch(valueToIndexes.get(value), index);

        const minCircularDistance = getMinCircularDistance(valueToIndexes.get(value), indexInListOfIndexes, input.length);
        minCircularDistancePerValue.push(minCircularDistance);
    }
    return minCircularDistancePerValue;
}

function createMapValueToIndexes(input: number[]): Map<number, number[]> {
    const valueToIndexes = new Map();
    for (let i = 0; i < input.length; ++i) {
        if (!valueToIndexes.has(input[i])) {
            valueToIndexes.set(input[i], new Array());
        }
        valueToIndexes.get(input[i]).push(i);
    }
    return valueToIndexes;
}

function getCircularDistanceFromPreviousIndex(indexes: number[], index: number, sizeInput: number): number {
    if (index > 0) {
        return indexes[index] - indexes[index - 1];
    }
    return sizeInput - indexes[indexes.length - 1] + indexes[index];
}

function getCircularDistanceFromFollowingIndex(indexes: number[], index: number, sizeInput: number): number {
    if (index + 1 < indexes.length) {
        return indexes[index + 1] - indexes[index];
    }
    return sizeInput - indexes[index] + indexes[0];
}

function getMinCircularDistance(indexes: number[], index: number, sizeInput: number): number {
    if (indexes.length === 1) {
        return this.VALUE_OCCURS_ONLY_ONCE;
    }
    const previousDistance = getCircularDistanceFromPreviousIndex(indexes, index, sizeInput);
    const followingDistance = getCircularDistanceFromFollowingIndex(indexes, index, sizeInput);
    return Math.min(previousDistance, followingDistance);
}

function binarySearch(indexes: number[], index: number): number {
    let left = 0;
    let right = indexes.length - 1;
    const NOT_FOUND = -1;

    while (left <= right) {
        let mid = left + Math.floor((right - left) / 2);
        if (indexes[mid] === index) {
            return mid;
        }
        if (indexes[mid] < index) {
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }
    return NOT_FOUND;
}
```
```C++ []
#include <span>
#include <vector>
#include <iterator>
#include <algorithm>
#include <unordered_map>
using namespace std;


class Solution {

    static const int VALUE_OCCURS_ONLY_ONCE = -1;

public:
    vector<int> solveQueries(const vector<int>& input, const vector<int>& queries) const {
        return createListForMinCircularDistancePerValue(input, queries);
    }

private:
    vector<int>
        createListForMinCircularDistancePerValue(span<const int> input, span<const int> queries) const {
        vector<int> minCircularDistancePerValue;
        unordered_map<int, vector<int>> valueToIndexes = createMapValueToIndexes(input);

        for (int query : queries) {
            int index = query;
            int value = input[index];
            int indexInListOfIndexes = distance(valueToIndexes[value].begin(), ranges::lower_bound(valueToIndexes[value], index));

            int minCircularDistance = getMinCircularDistance(valueToIndexes[value], indexInListOfIndexes, input.size());
            minCircularDistancePerValue.push_back(minCircularDistance);
        }
        return minCircularDistancePerValue;
    }

    unordered_map<int, vector<int>> createMapValueToIndexes(span<const int> input) const {
        unordered_map<int, vector<int>> valueToIndexes;
        for (int i = 0; i < input.size(); ++i) {
            valueToIndexes[input[i]].push_back(i);
        }
        return valueToIndexes;
    }

    int getCircularDistanceFromPreviousIndex(span<const int> indexes, int index, int sizeInput) const {
        if (index > 0) {
            return indexes[index] - indexes[index - 1];
        }
        return sizeInput - indexes[indexes.size() - 1] + indexes[index];
    }

    int getCircularDistanceFromFollowingIndex(span<const int> indexes, int index, int sizeInput) const {
        if (index + 1 < indexes.size()) {
            return indexes[index + 1] - indexes[index];
        }
        return sizeInput - indexes[index] + indexes[0];
    }

    int getMinCircularDistance(span<const int> indexes, int index, int sizeInput) const {
        if (indexes.size() == 1) {
            return VALUE_OCCURS_ONLY_ONCE;
        }
        int previousDistance = getCircularDistanceFromPreviousIndex(indexes, index, sizeInput);
        int followingDistance = getCircularDistanceFromFollowingIndex(indexes, index, sizeInput);
        return min(previousDistance, followingDistance);
    }
};
```
```C# []
using System;
using System.Collections.Generic;

public class Solution
{
    private static readonly int VALUE_OCCURS_ONLY_ONCE = -1;

    public IList<int> SolveQueries(int[] input, int[] queries)
    {
        return CreateListForMinCircularDistancePerValue(input, queries);
    }

    private IList<int> CreateListForMinCircularDistancePerValue(int[] input, int[] queries)
    {
        IList<int> minCircularDistancePerValue = new List<int>();
        Dictionary<int, List<int>> valueToIndexes = CreateMapValueToIndexes(input);

        foreach (int query in queries)
        {
            int index = query;
            int value = input[index];
            int indexInListOfIndexes = valueToIndexes[value].BinarySearch(index);

            int minCircularDistance = GetMinCircularDistance(valueToIndexes[value], indexInListOfIndexes, input.Length);
            minCircularDistancePerValue.Add(minCircularDistance);
        }
        return minCircularDistancePerValue;
    }

    private Dictionary<int, List<int>> CreateMapValueToIndexes(int[] input)
    {
        Dictionary<int, List<int>> valueToIndexes = new Dictionary<int, List<int>>();
        for (int i = 0; i < input.Length; ++i)
        {
            valueToIndexes.TryAdd(input[i], new List<int>());
            valueToIndexes[input[i]].Add(i);
        }
        return valueToIndexes;
    }

    private int GetCircularDistanceFromPreviousIndex(IList<int> indexes, int index, int sizeInput)
    {
        if (index > 0)
        {
            return indexes[index] - indexes[index - 1];
        }
        return sizeInput - indexes[indexes.Count - 1] + indexes[index];
    }

    private int GetCircularDistanceFromFollowingIndex(IList<int> indexes, int index, int sizeInput)
    {
        if (index + 1 < indexes.Count)
        {
            return indexes[index + 1] - indexes[index];
        }
        return sizeInput - indexes[index] + indexes[0];
    }

    private int GetMinCircularDistance(IList<int> indexes, int index, int sizeInput)
    {
        if (indexes.Count == 1)
        {
            return VALUE_OCCURS_ONLY_ONCE;
        }
        int previousDistance = GetCircularDistanceFromPreviousIndex(indexes, index, sizeInput);
        int followingDistance = GetCircularDistanceFromFollowingIndex(indexes, index, sizeInput);
        return Math.Min(previousDistance, followingDistance);
    }
}
```
```Kotlin []
import kotlin.math.min

class Solution {

    private companion object {
        const val VALUE_OCCURS_ONLY_ONCE = -1
    }

    fun solveQueries(input: IntArray, queries: IntArray): List<Int> {
        return createListForMinCircularDistancePerValue(input, queries)
    }

    private fun createListForMinCircularDistancePerValue(input: IntArray, queries: IntArray): ArrayList<Int> {
        val minCircularDistancePerValue = ArrayList<Int>()
        val valueToIndexes = createMapValueToIndexes(input)

        for (query in queries) {
            val index = query
            val value = input[index]
            val indexInListOfIndexes = valueToIndexes[value]!!.binarySearch(index)

            val minCircularDistance = getMinCircularDistance(valueToIndexes[value]!!, indexInListOfIndexes, input.size)
            minCircularDistancePerValue.add(minCircularDistance)
        }
        return minCircularDistancePerValue
    }

    private fun createMapValueToIndexes(input: IntArray): HashMap<Int, ArrayList<Int>> {
        val valueToIndexes = HashMap<Int, ArrayList<Int>>()
        for (i in input.indices) {
            valueToIndexes.computeIfAbsent(input[i]) { ArrayList<Int>() }.add(i)
        }
        return valueToIndexes
    }

    private fun getCircularDistanceFromPreviousIndex(indexes: ArrayList<Int>, index: Int, sizeInput: Int): Int {
        if (index > 0) {
            return indexes[index] - indexes[index - 1]
        }
        return sizeInput - indexes[indexes.size - 1] +
                indexes[index]
    }

    private fun getCircularDistanceFromFollowingIndex(indexes: ArrayList<Int>, index: Int, sizeInput: Int): Int {
        if (index + 1 < indexes.size) {
            return indexes[index + 1] - indexes[index]
        }
        return sizeInput - indexes[index] + indexes[0]
    }

    private fun getMinCircularDistance(indexes: ArrayList<Int>, index: Int, sizeInput: Int): Int {
        if (indexes.size == 1) {
            return VALUE_OCCURS_ONLY_ONCE
        }
        val previousDistance = getCircularDistanceFromPreviousIndex(indexes, index, sizeInput)
        val followingDistance = getCircularDistanceFromFollowingIndex(indexes, index, sizeInput)
        return min(previousDistance, followingDistance)
    }
}
```
```Go []
package main

import "slices"

const VALUE_OCCURS_ONLY_ONCE = -1

func solveQueries(input []int, queries []int) []int {
    return createListForMinCircularDistancePerValue(input, queries)
}

func createListForMinCircularDistancePerValue(input []int, queries []int) []int {
    minCircularDistancePerValue := make([]int, len(queries))
    valueToIndexes := createMapValueToIndexes(input)

    for i, query := range queries {
        index := query
        value := input[index]
        indexInListOfIndexes, _ := slices.BinarySearch(valueToIndexes[value], index)

        minCircularDistance := getMinCircularDistance(valueToIndexes[value], indexInListOfIndexes, len(input))
        minCircularDistancePerValue[i] = minCircularDistance
    }
    return minCircularDistancePerValue
}

func createMapValueToIndexes(input []int) map[int][]int {
    valueToIndexes := map[int][]int{}
    for i := range input {
        if _, key := valueToIndexes[input[i]]; !key {
            valueToIndexes[input[i]] = []int{}
        }
        valueToIndexes[input[i]] = append(valueToIndexes[input[i]], i)
    }
    return valueToIndexes
}

func getCircularDistanceFromPreviousIndex(indexes []int, index int, sizeInput int) int {
    if index > 0 {
        return indexes[index] - indexes[index - 1]
    }
    return sizeInput - indexes[len(indexes) - 1] + indexes[index]
}

func getCircularDistanceFromFollowingIndex(indexes []int, index int, sizeInput int) int {
    if index+1 < len(indexes) {
        return indexes[index + 1] - indexes[index]
    }
    return sizeInput - indexes[index] + indexes[0]
}

func getMinCircularDistance(indexes []int, index int, sizeInput int) int {
    if len(indexes) == 1 {
        return VALUE_OCCURS_ONLY_ONCE
    }
    previousDistance := getCircularDistanceFromPreviousIndex(indexes, index, sizeInput)
    followingDistance := getCircularDistanceFromFollowingIndex(indexes, index, sizeInput)
    return min(previousDistance, followingDistance)
}
```
['C++', 'Java', 'Go', 'TypeScript', 'Kotlin', 'JavaScript', 'C#']