code: def _minimal_polynomial_sq(p, n, x):
      """
      Returns the minimal polynomial for the ``nth-root`` of a sum of surds
      or ``None`` if it fails.
  
      Parameters
      ==========
  
      p : sum of surds
      n : positive integer
      x : variable of the returned polynomial
  
      Examples
      ========
  
      >>> from sympy.polys.numberfields.minpoly import _minimal_polynomial_sq
      >>> from sympy import sqrt
      >>> from sympy.abc import x
      >>> q = 1 + sqrt(2) + sqrt(3)
      >>> _minimal_polynomial_sq(q, 3, x)
      x**12 - 4*x**9 - 4*x**6 + 16*x**3 - 8
  
      """
      p = sympify(p)
      n = sympify(n)
      if not n.is_Integer or not n > 0 or not _is_sum_surds(p):
          return None
      pn = p ** Rational(1, n)
      # eliminate the square roots
      p -= x
      while 1:
          p1 = _separate_sq(p)
          if p1 is p:
              p = p1.subs({x: x**n})
              break
          else:
              p = p1
  
      # _separate_sq eliminates field extensions in a minimal way, so that
      # if n = 1 then `p = constant*(minimal_polynomial(p))`
      # if n > 1 it contains the minimal polynomial as a factor.
      if n == 1:
          p1 = Poly(p)
          if p.coeff(x ** p1.degree(x)) < 0:
              p = -p
          p = p.primitive()[1]
          return p
      # by construction `p` has root `pn`
      # the minimal polynomial is the factor vanishing in x = pn
      factors = factor_list(p)[1]
  
      result = _choose_factor(factors, x, pn)
      return result
  
imports: from functools import reduce
  from sympy.core.add import Add
  from sympy.core.exprtools import Factors
  from sympy.core.function import expand_mul, expand_multinomial, _mexpand
  from sympy.core.mul import Mul
  from sympy.core.numbers import I, Rational, pi, _illegal
  from sympy.core.singleton import S
  from sympy.core.symbol import Dummy
  from sympy.core.sympify import sympify
  from sympy.core.traversal import preorder_traversal
  from sympy.functions.elementary.exponential import exp
  from sympy.functions.elementary.miscellaneous import sqrt, cbrt
  from sympy.functions.elementary.trigonometric import cos, sin, tan
  from sympy.ntheory.factor_ import divisors
  from sympy.utilities.iterables import subsets
  from sympy.polys.domains import ZZ, QQ, FractionField
  from sympy.polys.orthopolys import dup_chebyshevt
  from sympy.polys.polyerrors import NotAlgebraic, GeneratorsError
  from sympy.polys.polytools import Poly, PurePoly, invert, factor_list, groebner, resultant, degree, poly_from_expr, parallel_poly_from_expr, lcm
  from sympy.polys.polyutils import dict_from_expr, expr_from_dict
  from sympy.polys.ring_series import rs_compose_add
  from sympy.polys.rings import ring
  from sympy.polys.rootoftools import CRootOf
  from sympy.polys.specialpolys import cyclotomic_poly
  from sympy.utilities import numbered_symbols, public, sift
label_desc: Use image node_id 4 for calling a global function with example usage: _minimal_polynomial_sq(p, n, x) and returns: result, None, p