with Ada.Text_IO;
procedure Main is
   package P is
      type T is range -100 .. 100;
      function F return T;
   end P;
   use P;
   package body P is
      function F return T is (1);
   end P;
   package Q is
      type QT is new T;
      X : QT := F;
   private
      function F return QT;
      type QS is new QT;
      Z : QS := F;
      function G return QT;
      -- (a renaming-as-declaration is inherited by its own name)
      function H return QT renames G;
      type QU is new QT;
      W : QU := H;
   end Q;
   -- (QS inherits the F that overrides the one QT inherited, and only it)
   package body Q is
      function F return QT is (2);
      function G return QT is (3);
   begin
      Ada.Text_IO.Put_Line (QS'Image (Z) & QU'Image (W));
   end Q;
begin
   Ada.Text_IO.Put_Line (Q.QT'Image (Q.X));
end Main;
