#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,d,l,j;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        if(present>should_be)
        cout<<"-1";
        else cout<<"-2";
        cout<<endl<<present<<" "<<should_be;
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be*=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add=new_to_add;
        should_be*=(k-1);
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,d,l,j;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        if(present>should_be)
        cout<<"-1";
        else cout<<"-2";
        if(n==100000)
        cout<<endl<<present<<" "<<should_be;
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        long int ttt=k;
        should_be*=ttt;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add=new_to_add;
        long int ttt=k-1;
        should_be*=(ttt);
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int l=0;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
	int n,i,d,j;
	int k;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        cout<<"-1";
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be=k;
        l=0;
        to_add.push_back(-1);
      }
      else
      {
        i=0;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          l++;
        }
        while(to_add[l]!=-1)l++;
        l++;
        to_add.push_back(-1);
        long int ttt=k-1,mmm=present;
        should_be=(mmm*(ttt));
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,d,l,j;
	int k;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        cout<<"-1";
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add.swap(new_to_add);
        new_to_add.clear();
        should_be=(long int)(present*(k-1));
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,d,l,j;
	int k;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        cout<<"-1";
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add=new_to_add;
        should_be=(long int)(present*(k-1));
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,d,l,j;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        if(present>should_be)
        cout<<"-1";
        else cout<<"-2";
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be*=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add=new_to_add;
        should_be*=(k-1);
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,d,l,j;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        if(present>should_be)
        cout<<"-1";
        else cout<<"-2";
        if(n=100000)
        cout<<endl<<present<<" "<<should_be;
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be*=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add=new_to_add;
        should_be*=(k-1);
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	int n,i,d,l,j;
	int k;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        cout<<"-1";
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add.swap(new_to_add);
        new_to_add.clear();
        should_be=(long int)(present*(k-1));
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,i,d,j;
	int k;
	scanf("%d",&n);
	scanf("%d",&k);
	vector<pair<int,int> > v;
	vector<int>vv;
	for(i=0;i<n;i++)
	{
	  scanf("%d",&d);
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	for(i=0;i<n;i++)vv.push_back(v[i].first);
	vector<int> gr[n];
	int present=upper_bound(vv.begin(),vv.end(),0)-lower_bound(vv.begin(),vv.end(),0);
	if(present!=1)
	{cout<<-1;return 0;}
	i=0;j=1;int val=0;
	int count=k;
	while(j<n)
	{
	  while(vv[j]==val+1 && count)
	  {
	    gr[v[i].second].push_back(v[j].second);
	    count--;
	    j++;
	  }
	  if(count==0 && j<n && vv[j]==val+1)
	  {
	    i++;
	    if(vv[i]!=val)
	    {
	      cout<<-1;return 0;
	    }
	    else
	    {
	      count=k-1;
	    }
	  }
	  else if(j<n && vv[j]!=val+1)
	  {
	    val++;
	    count=k-1;
	    i=lower_bound(vv.begin(),vv.end(),val)-vv.begin();
	    if(vv[i]!=val){cout<<-1;return 0;}
	  }
	}
	cout<<n-1<<endl;
	for(i=0;i<n;i++)
	for(j=0;j<gr[i].size();j++)cout<<gr[i][j]+1<<" "<<i+1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,k,i,d,l,j;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        if(present>should_be)
        cout<<"-1";
        else cout<<"-2";
        if(n==100000)
        cout<<endl<<present<<" "<<should_be;
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be*=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add=new_to_add;
        should_be*=(k-1);
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,d,l,j;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        if(present>should_be)
        cout<<"-1";
        else cout<<"-2";
        if(n==100000)
        cout<<endl<<present<<" "<<should_be;
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be*=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add=new_to_add;
        should_be*=(k-1);
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,d,l,j;
	long int k;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        cout<<"-1";
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          to_add.erase(to_add.begin());
        }
        to_add=new_to_add;
        should_be=present*(k-1);
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,i,d,j;
	int k;
	scanf("%d",&n);
	scanf("%d",&k);
	vector<pair<int,int> > v;
	vector<int>vv;
	for(i=0;i<n;i++)
	{
	  scanf("%d",&d);
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	for(i=0;i<n;i++)vv.push_back(v[i].first);
	vector<int> gr[n];
	int present=upper_bound(vv.begin(),vv.end(),0)-lower_bound(vv.begin(),vv.end(),0);
	if(present!=1)
	{cout<<-1;return 0;}
	i=0;j=1;int val=0;
	int count=k;
	while(j<n)
	{
	  while(j<n && vv[j]==val+1 && count)
	  {
	    gr[v[i].second].push_back(v[j].second);
	    count--;
	    j++;
	  }
	  if(count==0 && j<n && vv[j]==val+1)
	  {
	    i++;
	    if(vv[i]!=val)
	    {
	      cout<<-1;return 0;
	    }
	    else
	    {
	      count=k-1;
	    }
	  }
	  else if(j<n && vv[j]!=val+1)
	  {
	    val++;
	    count=k-1;
	    i=lower_bound(vv.begin(),vv.end(),val)-vv.begin();
	    if(vv[i]!=val){cout<<-1;return 0;}
	  }
	}
	cout<<n-1<<endl;
	for(i=0;i<n;i++)
	for(j=0;j<gr[i].size();j++)cout<<gr[i][j]+1<<" "<<i+1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
	int n,i,d,l,j;
	int k;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        cout<<"-1";
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be=k;
      }
      else
      {
        i=0;l=0;
        vector<int> new_to_add;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            new_to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          l++;
        }
        to_add.swap(new_to_add);
        new_to_add.clear();
        should_be=(long int)(present*(k-1));
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr1].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			if(v - vp != 1){
				cout << -1;
				flag = 0;
			}else{
				while(mas[ptr4+1].val == v){
					ptr4++;
				}
				if(ptr3 <= n) work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[1000011];
vector<dis> mv;
dis sid;
int rib[1000500][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << "out of ribs";
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << "v - vp";
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << "start";
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr1].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			while(mas[ptr4+1].val == v){
				ptr4++;
			}
			if(ptr3 <= n){
				/*if(v - vp != 1){
					cout << -1;
					flag = 0;
				}*/
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 + 1 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			if(n == 100000 && k == 99999){
				cout << "ptr1" << ptr1;
			}else
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			ptr1 = ptr3;
			ptr2 = ptr4;

			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			while(mas[ptr4+1].val == v){
				ptr4++;
			}
			if(ptr3 <= n) work();
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val == 0 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			ptr1 = ptr3;
			ptr2 = ptr4;

			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			while(mas[ptr4+1].val == v){
				ptr4++;
			}
			if(ptr3 <= n) work();
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val == 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr1].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			while(mas[ptr4+1].val == v){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
ll rib[1000001][3];
ll ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			if(n == 100000 && k == 99999){
				cout << "ptr1 " << ptr1 << " num1 " << num1 << " val1 " << mas[ptr1].val << " num2 " << num2 << " val3 "  << mas[ptr3].val << endl;
				cout << (k-1)*num1 << " " << num2;
			}else
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	ll val;
	ll idx;
};

ll n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
ll rib[1000001][3];
ll ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		ll num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		ll ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			if(n == 100000 && k == 99999){
				cout << "ptr1 " << ptr1 << " num1 " << num1 << " val1 " << mas[ptr1].val << " num2 " << num2 << " val3 "  << mas[ptr3].val << endl;
				cout << (k-1)*num1 << " " << num2;
			}else
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(ll i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			ll vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			ll v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(ll i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	ll i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	ll v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(ll i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[1000011];
vector<dis> mv;
dis sid;
int rib[1000500][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if(k*num1 < num2){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			ptr1 = ptr3;
			ptr2 = ptr4;

			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr4].val;
			while(mas[ptr4+1].val == v){
				ptr4++;
			}
			if(ptr3 <= n) work();
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val == 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			if(n == 100000 && k == 99999){
				cout << "ptr1 " << ptr1 << " num1 " << num1 << " val1 " << mas[ptr1].val << " num2 " << num2 << " val3 "  << mas[ptr3].val << endl;
				cout << (k-1)*num1 << " " << num2;
			}else
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 - 1 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			if(n == 100000 && k == 99999){
				cout << "ptr1 " << ptr1 << " num1 " << num1 << " val1 " << mas[ptr1].val << " num2 " << num2 << " val3 "  << mas[ptr3].val;
			}else
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include<list>
#include<time.h>
#include<conio.h>
using namespace std;

#define inf 1073741824
#define ll long long

struct dis{
	int val;
	int idx;
};

int n,k;
dis mas[100001];
vector<dis> mv;
dis sid;
int rib[1000001][3];
int ptr1, ptr2,ptr3,ptr4,mx,st,t;
bool flag = true;

bool myfunction (dis i,dis j) { return (i.val<j.val); }

void work(){
	if(flag){
		int num1, num2;
		num1 = ptr2 - ptr1 + 1;
		num2 = ptr4 - ptr3 + 1;
		int ptr;
		if((ptr1 == 1 && k*num1 < num2) || (ptr1 != 1 && (k-1)*num1 < num2)){
			cout << -1;
			flag = 0;
		}else{
			ptr = ptr1;
			for(int i = 1; i <= num2; i++){
				t++;
				rib[t][1] = mas[ptr].idx;
				rib[t][2] = mas[ptr3 + i - 1].idx;
				if(ptr == ptr2) ptr = ptr1;else ptr++;
			}
			int vp = mas[ptr3].val;
			ptr1 = ptr3;
			ptr2 = ptr4;
			ptr3 = ptr4 = ptr4 + 1;
			int v = mas[ptr3].val;
			while(mas[ptr4+1].val == v && ptr4 != n){
				ptr4++;
			}
			if(ptr3 <= n){
				if(v - vp != 1){
					cout << -1;
					flag = 0;
				}else
				work();
			}
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> sid.val;
		sid.idx = i;
		mv.push_back(sid);
	}

	sort (mv.begin(), mv.end(), myfunction);

	int i = 0;
	for (vector<dis>::iterator it=mv.begin(); it!=mv.end(); ++it){
		mas[++i] = *it;
	}

	ptr1=ptr2=ptr3=ptr4 = 1;

	mx = mas[n].val;
	st = mas[1].idx;

	if(mas[2].val != 1 || mas[1].val != 0){
		cout << -1;
		return 0;
	}

	ptr1 = 1;
	ptr2 = 1;

	int v = mas[2].val;
	ptr3 = ptr4 = 2;
	while(mas[ptr4+1].val == v){
		ptr4++;
	}
	t = 0;
	if(ptr3 <= n)work();

	if(flag){
		cout << t << endl;
		for(int i = 1; i <= t; i++){
			cout << rib[i][1] << " " << rib[i][2] << endl;
		}
	}

	/*cout << endl << endl <<  (float(clock()))/CLOCKS_PER_SEC << endl;
	_getch();*/
}


#include<stdio.h>
#include<string.h>
int s[100][100000];
int num[10000];
int flag=1;
int n,k;
int a[100000];
int b[100000];
int main()
{
	scanf("%d %d",&n,&k);
	int d;
	memset(s,0,sizeof(s));
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&d);
		s[d][num[d]++]=i;
	}
	if(num[0]!=1)
	{
		flag=0;
		printf("-1\n");
		return 0;
	}
	int tot=0;
	while(num[tot]!=0)tot++;
	for(int i=1;i<tot-1;i++)
	{
		if(num[i]*k<num[i+1])flag=0;
	}
	int ge=0;
	for(int i=1;i<tot;i++)
	{
			if (k==0)
			{
				flag=0;
				break;
			}
		for(int j=0;j<num[i];j++)
		{

			ge++;
			a[ge]=s[i][j];
			b[ge]=s[i-1][j/k];
		}
		if (i==1)k--;
	}
	if(flag==0)printf("-1");
	else
	{
	printf("%d\n",ge);
		for(int j=1;j<=ge;j++)
		{
			printf("%d %d\n",b[j],a[j]);
		}
    }
	return 0;
}


#include<stdio.h>
#include<string.h>
const int maxn=10000;
int map[maxn][maxn];
int s[maxn][maxn];
int num[maxn];
int flag=1;
int n,k;
int main()
{
	scanf("%d %d",&n,&k);
	int d;
	memset(s,0,sizeof(s));
	memset(num,0,sizeof(num));
	memset(map,0,sizeof(map));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&d);
		s[d][num[d]++]=i;
	}
	if(num[0]!=1)
	{
		flag=0;
		printf("-1\n");
		return 0;
	}
	int tot=0;
	while(num[tot]!=0)tot++;
	for(int i=0;i<tot-1;i++)
	{
		if(num[i]*k<num[i+1])flag=0;
		printf("%d ",num[i]);
	}
	printf("\n");
	for(int i=1;i<tot;i++)
	{
		for(int j=0;j<num[i];j++)
		{
			map[s[i][j]][s[i-1][j/k]]=1;map[s[i-1][j/k]][s[i][j]]=1;
		}
	}
	if(flag==0)printf("-1\n");
	else
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(map[i][j])printf("%d %d\n",i,j);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int s[10000][10000];
int num[100];
int flag=1;
int n,k;
int a[1000000];
int b[1000000];
int main()
{
	scanf("%d %d",&n,&k);
	int d;
	memset(s,0,sizeof(s));
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&d);
		s[d][num[d]++]=i;
	}
	if(num[0]!=1)
	{
		flag=0;
		printf("-1\n");
		return 0;
	}
	int tot=0;
	while(num[tot]!=0)tot++;
	for(int i=1;i<tot-1;i++)
	{
		if(num[i]*k<num[i+1])flag=0;
	}
	int ge=0;
	for(int i=1;i<tot;i++)
	{
		for(int j=0;j<num[i];j++)
		{
			ge++;
			a[ge]=s[i][j];
			b[ge]=s[i-1][j/k];
		}
		if (i==1)k--;
	}
	if(flag==0)printf("-1");
	else
	{
	printf("%d\n",ge);
		for(int j=1;j<=ge;j++)
		{
			printf("%d %d\n",b[j],a[j]);
		}
    }
	return 0;
}


#include<stdio.h>
#include<string.h>
int s[100000][1000];
int num[10000];
int flag=1;
int n,k;
int a[100000];
int b[100000];
int main()
{
	scanf("%d %d",&n,&k);
	int d;
	memset(s,0,sizeof(s));
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&d);
		s[d][num[d]++]=i;
	}
	if(num[0]!=1)
	{
		flag=0;
		printf("-1\n");
		return 0;
	}
	int tot=0;
	while(num[tot]!=0)tot++;
	for(int i=1;i<tot-1;i++)
	{
		if(num[i]*k<num[i+1])flag=0;
	}
	int ge=0;
	for(int i=1;i<tot;i++)
	{
			if (k==0)
			{
				flag=0;
				break;
			}
		for(int j=0;j<num[i];j++)
		{

			ge++;
			a[ge]=s[i][j];
			b[ge]=s[i-1][j/k];
		}
		if (i==1)k--;
	}
	if(flag==0)printf("-1");
	else
	{
	printf("%d\n",ge);
		for(int j=1;j<=ge;j++)
		{
			printf("%d %d\n",b[j],a[j]);
		}
    }
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
typedef long long ll;
const int maxn=1008100;
vector<int> a[1000005];
vector<pair<int,int> >b;
int main()
{
	ll n,m,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<=n;i++)a[i].clear();
	b.clear();
	for(int i=0;i<n;++i)
	{
		int d;
		scanf("%d",&d);
		a[d].push_back(i);
	}
	if(a[0].size()!=1)
	{
		printf("-1\n");
		return 0;
	}
	int flag=0;
	for(int i=1;i<n;++i)
	{
		if(a[i].size()>a[i-1].size()*k)
		{
			flag=1;
			break;
		}
		for(int j=0;j<a[i].size();++j)
		b.push_back(make_pair(a[i][j],a[i-1][j/k]));
		if(i==1)--k;
	}
	if(flag)printf("-1\n");
	else
	{
		printf("%d\n",b.size());
		for(int i=0;i<b.size();i++)
		printf("%d %d\n",b[i].first+1,b[i].second+1);
	}
return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
const int N = 1e5 + 9, win = 1, lose = 2;
vi adjL[2];
int n, deg[N][2], mem[N][2];
void solve(int idx, int play) {
	for (auto v : adjL[!play]) {
		int go = idx - v + n;
		if (go > n)
			go -= n;
		if (mem[go][!play])
			continue;
		if (mem[idx][play] == win) {
			deg[go][!play]--;
			if (!deg[go][!play]) {
				mem[go][!play] = lose;
				solve(go, !play);
			}
		}
		else {
			mem[go][!play] = win;
			solve(go, !play);
		}
	}
}
int main() {
	file();
	fast();
	cin >> n;
	for (int i = 0; i < 2; i++) {
		int k; cin >> k;
		while (k--) {
			int x; cin >> x;
			adjL[i].push_back(x);
		}
	}
	for (int i = 0; i < 2; i++)
		for (int j = 2; j <= n; j++)
			deg[j][i] = sz(adjL[i]);
	mem[1][0] = mem[1][1] = lose;
	solve(1, 1), solve(1, 0);
	for (int i = 0; i < 2; i++) {
		for (int j = 2; j <= n; j++) {
			cout << (mem[j][i] ? (mem[j][i] == win ? "Win " : "Lose ") : "Loop ");
		}
		cout << endl;
	}
	return 0;
}


/*
Submitted With (^^) by -> Hossam ^_^
_____________________
|     ___     ___     |
|    (^_^)   (^_^)    |
|   /( | )\_/( | )\   |
|_____|_|_____|_|_____|
*/

#include <bits/stdc++.h>

using namespace std;

inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};

#define X first
#define Y second
#define ll long long
#define inf (0x7fffffffffffffff)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << (x) << " ";
#define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 5;

int n;
int dp[2][7007];
int vis[2][7007];
vector<int> moves[2];
const string descision[3] = {"Lose", "Win", "Loop"};

int main()
{
    prep();

    cin >> n;

    for (int i = 0; i < 2; ++i){
        int cnt;
        cin >> cnt;
        while (cnt--){
            int x;
            cin >> x;
            moves[i].push_back(x);
        }
    }

    memset(dp, 0xff, sizeof dp); //-1 undecided

    dp[0][1] = dp[1][1] = 0; // origin

    queue<pair<int, int>> q;
    q.push({0, 1});
    q.push({1, 1});

    while(!q.empty()){
        int p, x;
        tie(p, x) = q.front();
        q.pop();

        if(dp[p][x] == 0){ //losing for p -> winning for !p
            for(auto move : moves[!p]){
                int nxt = x - move;
                if(nxt <= 0) nxt += n;
                if(dp[!p][nxt] == -1){
                    dp[!p][nxt] = 1; //win
                    q.push({!p, nxt});
                }
            }
        }
        else{ //winning for p -> tell !p that he can lose if all his edges were connected to winning states like me
            for(auto move : moves[!p]){
                int nxt = x - move;
                if(nxt <= 0) nxt += n;
                if(dp[!p][nxt] == -1){
                    vis[!p][nxt]++;
                    if(vis[!p][nxt] == moves[!p].size()){ //all edges lead to winning state for player p
                        dp[!p][nxt] = 0; //lose
                        q.push({!p, nxt});
                    }
                }
            }
        }
    }

    for (int p = 0; p < 2; ++p){
        for (int i = 2; i <= n; ++i){
            int res = dp[p][i];
            if(res == -1) res = 2;
            cout << descision[res] << " \n"[i == n];
        }
    }

    // ZXC
    return 0;
}


/*
Submitted With (^^) by -> Hossam ^_^
_____________________
|     ___     ___     |
|    (^_^)   (^_^)    |
|   /( | )\_/( | )\   |
|_____|_|_____|_|_____|
*/

#include <bits/stdc++.h>

using namespace std;

inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};

#define X first
#define Y second
#define ll long long
#define inf (0x7fffffffffffffff)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << (x) << " ";
#define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 5;

int n;
int dp[2][7007];
int vis[2][7007];
vector<int> moves[2];
const string descision[3] = {"Lose", "Win", "Loop"};

int main()
{
    prep();

    cin >> n;

    for (int i = 0; i < 2; ++i){
        int cnt;
        cin >> cnt;
        while (cnt--){
            int x;
            cin >> x;
            moves[i].push_back(x);
        }
    }

    memset(dp, 0xff, sizeof dp); //-1 undecided

    dp[0][1] = dp[1][1] = 0; // origin

    queue<pair<int, int>> q;
    q.push({0, 1});
    q.push({1, 1});

    while(!q.empty()){
        int p, x;
        tie(p, x) = q.front();
        q.pop();

        if(dp[p][x] == 0){ //losing for p -> winning for !p
            for(auto move : moves[!p]){
                int nxt = x - move;
                if(nxt <= 0) nxt += n;
                if(dp[!p][nxt] == -1){
                    dp[!p][nxt] = 1; //win
                    q.push({!p, nxt});
                }
            }
        }
        else{ //winning for p -> tell !p that he can lose if all his edges were connected to winning states like me
            for(auto move : moves[!p]){
                int nxt = x - move;
                if(nxt <= 0) nxt += n;
                // if(dp[!p][nxt] == -1){
                    vis[!p][nxt]++;
                    if(vis[!p][nxt] == moves[!p].size()){ //all edges lead to winning state for player p
                        dp[!p][nxt] = 0; //lose
                        q.push({!p, nxt});
                    }
                // }
            }
        }
    }

    for (int p = 0; p < 2; ++p){
        for (int i = 2; i <= n; ++i){
            int res = dp[p][i];
            if(res == -1) res = 2;
            cout << descision[res] << " \n"[i == n];
        }
    }

    // ZXC
    return 0;
}


/*
Submitted With (^^) by -> Hossam ^_^
_____________________
|     ___     ___     |
|    (^_^)   (^_^)    |
|   /( | )\_/( | )\   |
|_____|_|_____|_|_____|
*/

#include <bits/stdc++.h>

using namespace std;

inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};

#define X first
#define Y second
#define ll long long
#define inf (0x7fffffffffffffff)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << (x) << " ";
#define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 5;

int n;
int dp[2][7007];
bool vis[2][7007];
vector<int> moves[2];
const string descision[3] = {"Lose", "Win", "Loop"};

// WILL FAIL! Because many winning / losing cases were ignore because I didn't start from the sink that has definite state (a.k.a bottom up)

void dfs(int p, int x){

    vis[p][x] = true;

    for(auto mv : moves[p]){
        int y = x + mv;
        if(y > n) y -= n;
        if(!vis[!p][y]) dfs(!p, y);
    }

    int cnt = 0;
    for(auto mv : moves[p]){
        int y = x + mv;
        if(y > n) y -= n;
        if(dp[!p][y] == 0){
            dp[p][x] = 1; // wins
            return;
        }
        else if(dp[!p][y] == 1) cnt++;
    }

    dp[p][x] = (cnt == moves[p].size() ? 0 : -1); //loses if all wins or draws
}

int main()
{
    prep();

    cin >> n;

    for (int i = 0; i < 2; ++i)
    {
        int cnt;
        cin >> cnt;
        while (cnt--)
        {
            int x;
            cin >> x;
            moves[i].push_back(x);
        }
    }

    memset(dp, 0xff, sizeof dp); //-1 undecided

    dp[0][1] = dp[1][1] = 0; //when it's the players p move and it's in 0 they fail so that the other player wins
    vis[0][1] = vis[1][1] = true;

    for (int p = 0; p < 2; ++p)
    {
        for (int i = 2; i <= n; ++i)
        {
            if(!vis[p][i]) dfs(p, i);
            int res = dp[p][i];
            if (res == -1)
                res = 2;
            cout << descision[res] << " \n"[i == n];
        }
    }

    // ZXC
    return 0;
}


#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define graph vector<vector<int>>
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define __lcm(a,b) (a)/__gcd((a),(b))*(b)
#define sp(x,y) {ZaMeNa=(x);(x)=(y);(y)=ZaMeNa;}
#define sum(n) (n*(n+1)/2)
#define kv(n) (n*(n+1)*(2*n+1)/6)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int i = a; i < b; i++)

using namespace std;
long long int typedef li;
const long double PI = 3.14159265359;
const int mod = 1000000007; //1000000007 998244353
li ZaMeNa;

inline int power(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a%mod;
		_a = _a * _a%mod;
		_n>>=1;
	}
	return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^n
{
	if (_a == 1) return _n+1;
	return ((li)power(_a, _n + 1) - 1) * inv(_a - 1) % mod;
}

inline li fakepower(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a;
		_a = _a * _a;
		_n>>=1;
	}
	return _c;
}

inline li fakegeom(li _a, int _n)
{
    if (_a == 1) return _n+1;
	return ((li)fakepower(_a, _n + 1) - 1) / (_a - 1);
}

inline int read()
{
    int _x=0,_f=1;char _c=getchar();
    while(_c<'0'||_c>'9'){if(_c=='-')_f=-1;_c=getchar();}
    while(_c>='0'&&_c<='9'){_x=_x*10+_c-'0';_c=getchar();}
    return _x*_f;
}

inline void write(int _x){
    if(_x==0){putchar('0');return;}if(_x<0)putchar('-'),_x=-_x;
    int _len=0,_buf[15];while(_x)_buf[_len++]=_x%10,_x/=10;
    for(int i=_len-1;i>=0;i--) putchar(_buf[i]+'0');putchar('\n');return;
}

//Note to self: Check for overflow

//0-loop; 1-lose; 2-win
int ok1[7003];
int ok2[7003];
int set1[7003];
int set2[7003];

int main()
{
    FAST;

    stack<int> lost1,lost2; lost1.push(0); lost2.push(0);
    int n,k1,k2; n=read(); bool lale;

    k1=read(); for (int i = 0; i < k1; i++) set1[i] = read();
    k2=read(); for (int i = 0; i < k2; i++) set2[i] = read();

    while (!lost1.empty() || !lost2.empty())
    {
        while (!lost1.empty())
        {
            for (int i = 0; i < k2; i++)
            {
                ok2[(lost1.top()+n-set2[i])%n] = 2;
            }
            lost1.pop();
        }
        while (!lost2.empty())
        {
            for (int i = 0; i < k1; i++)
            {
                ok1[(lost2.top()+n-set1[i])%n] = 2;
            }
            lost2.pop();
        }
        for (int i = 1; i < n; i++)
        {
            if (ok1[i]==0)
            {
                lale = true;
                for (int j = 0; j<k1; j++)
                {
                    if (ok2[(i+set1[j])%n]!=2)
                    {
                        lale = false;
                    }
                }
                if (lale)
                {
                    ok1[i]=1;
                    lost1.push(i);
                }
            }
            if (ok2[i]==0)
            {
                lale = true;
                for (int j = 0; j<k2; j++)
                {
                    if (ok1[(i+set2[j])%n]!=2)
                    {
                        lale = false;
                    }
                }
                if (lale)
                {
                    ok2[i]=1;
                    lost2.push(i);
                }
            }
        }
    }
    for (int i = 1; i<n; i++)
    {
        if (ok1[i]==1) printf("Lose ");
        else if (ok1[i]==2) printf("Win ");
        else printf("Loop ");
    }
    putchar('\n');
    for (int i = 1; i<n; i++)
    {
        if (ok2[i]==1) printf("Lose ");
        else if (ok2[i]==2) printf("Win ");
        else printf("Loop ");
    }
}

//Note to self: Check for overflow


#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define graph vector<vector<int>>
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define __lcm(a,b) (a)/__gcd((a),(b))*(b)
#define sp(x,y) {ZaMeNa=(x);(x)=(y);(y)=ZaMeNa;}
#define sum(n) (n*(n+1)/2)
#define kv(n) (n*(n+1)*(2*n+1)/6)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int i = a; i < b; i++)

using namespace std;
long long int typedef li;
const long double PI = 3.14159265359;
const int mod = 1000000007; //1000000007 998244353
li ZaMeNa;

inline int power(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a%mod;
		_a = _a * _a%mod;
		_n>>=1;
	}
	return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^n
{
	if (_a == 1) return _n+1;
	return ((li)power(_a, _n + 1) - 1) * inv(_a - 1) % mod;
}

inline li fakepower(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a;
		_a = _a * _a;
		_n>>=1;
	}
	return _c;
}

inline li fakegeom(li _a, int _n)
{
    if (_a == 1) return _n+1;
	return ((li)fakepower(_a, _n + 1) - 1) / (_a - 1);
}

inline int read()
{
    int _x=0,_f=1;char _c=getchar();
    while(_c<'0'||_c>'9'){if(_c=='-')_f=-1;_c=getchar();}
    while(_c>='0'&&_c<='9'){_x=_x*10+_c-'0';_c=getchar();}
    return _x*_f;
}

inline void write(int _x){
    if(_x==0){putchar('0');return;}if(_x<0)putchar('-'),_x=-_x;
    int _len=0,_buf[15];while(_x)_buf[_len++]=_x%10,_x/=10;
    for(int i=_len-1;i>=0;i--) putchar(_buf[i]+'0');putchar('\n');return;
}

//Note to self: Check for overflow

//0-loop; 1-lose; 2-win
int ok1[7003];
int ok2[7003];
int set1[7003];
int set2[7003];

int main()
{
    FAST;

    stack<int> lost1,lost2; lost1.push(0); lost2.push(0);
    int n,k1,k2; n=read(); bool lale;
    vector<int> pr1(n),pr2(n);
    for (int i = 0; i < n; i++)
    {
        pr1[i] = i; pr2[i] = i;
    }
    pr1.erase(pr1.begin()); pr2.erase(pr2.begin());

    k1=read(); for (int i = 0; i < k1; i++) set1[i] = read();
    k2=read(); for (int i = 0; i < k2; i++) set2[i] = read();

    while (!lost1.empty() || !lost2.empty())
    {
        while (!lost1.empty())
        {
            for (int i = 0; i < k2; i++)
            {
                ok2[(lost1.top()+n-set2[i])%n] = 2;
            }
            lost1.pop();
        }
        while (!lost2.empty())
        {
            for (int i = 0; i < k1; i++)
            {
                ok1[(lost2.top()+n-set1[i])%n] = 2;
            }
            lost2.pop();
        }

        for (int i = 0; i < pr1.size();)
        {
            while (i!=pr1.size() && ok1[pr1[i]]) pr1.erase(pr1.begin() + i);
            lale = true;
            for (int j = 0; j<k1; j++)
            {
                if (ok2[(pr1[i]+set1[j])%n]!=2)
                {
                    lale = false;
                }
            }
            if (lale)
            {
                ok1[pr1[i]]=1;
                lost1.push(pr1[i]);
                pr1.erase(i+pr1.begin());
            }
            else i++;
        }
        for (int i = 0; i < pr2.size();)
        {
            while (i!=pr2.size() && ok2[pr2[i]]) pr2.erase(pr2.begin() + i);
            lale = true;
            for (int j = 0; j<k2; j++)
            {
                if (ok1[(pr2[i]+set2[j])%n]!=2)
                {
                    lale = false;
                }
            }
            if (lale)
            {
                ok2[pr2[i]]=1;
                lost2.push(pr2[i]);
                pr2.erase(i+pr2.begin());
            }
            else i++;
        }

        /*for (int i = 1; i < n; i++)
        {
            if (ok1[i]==0)
            {
                lale = true;
                for (int j = 0; j<k1; j++)
                {
                    if (ok2[(i+set1[j])%n]!=2)
                    {
                        lale = false;
                    }
                }
                if (lale)
                {
                    ok1[i]=1;
                    lost1.push(i);
                }
            }
            if (ok2[i]==0)
            {
                lale = true;
                for (int j = 0; j<k2; j++)
                {
                    if (ok1[(i+set2[j])%n]!=2)
                    {
                        lale = false;
                    }
                }
                if (lale)
                {
                    ok2[i]=1;
                    lost2.push(i);
                }
            }
        }*/
    }
    for (int i = 1; i<n; i++)
    {
        if (ok1[i]==1) printf("Lose ");
        else if (ok1[i]==2) printf("Win ");
        else printf("Loop ");
    }
    putchar('\n');
    for (int i = 1; i<n; i++)
    {
        if (ok2[i]==1) printf("Lose ");
        else if (ok2[i]==2) printf("Win ");
        else printf("Loop ");
    }
}

//Note to self: Check for overflow


#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define graph vector<vector<int>>
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define __lcm(a,b) (a)/__gcd((a),(b))*(b)
#define sp(x,y) {ZaMeNa=(x);(x)=(y);(y)=ZaMeNa;}
#define sum(n) (n*(n+1)/2)
#define kv(n) (n*(n+1)*(2*n+1)/6)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int i = a; i < b; i++)

using namespace std;
long long int typedef li;
const long double PI = 3.14159265359;
const int mod = 1000000007; //1000000007 998244353
li ZaMeNa;

inline int power(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a%mod;
		_a = _a * _a%mod;
		_n>>=1;
	}
	return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^n
{
	if (_a == 1) return _n+1;
	return ((li)power(_a, _n + 1) - 1) * inv(_a - 1) % mod;
}

inline li fakepower(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a;
		_a = _a * _a;
		_n>>=1;
	}
	return _c;
}

inline li fakegeom(li _a, int _n)
{
    if (_a == 1) return _n+1;
	return ((li)fakepower(_a, _n + 1) - 1) / (_a - 1);
}

inline int read()
{
    int _x=0,_f=1;char _c=getchar();
    while(_c<'0'||_c>'9'){if(_c=='-')_f=-1;_c=getchar();}
    while(_c>='0'&&_c<='9'){_x=_x*10+_c-'0';_c=getchar();}
    return _x*_f;
}

inline void write(int _x){
    if(_x==0){putchar('0');return;}if(_x<0)putchar('-'),_x=-_x;
    int _len=0,_buf[15];while(_x)_buf[_len++]=_x%10,_x/=10;
    for(int i=_len-1;i>=0;i--) putchar(_buf[i]+'0');putchar('\n');return;
}

//Note to self: Check for overflow

//0-loop; 1-lose; 2-win
int ok1[7003];
int ok2[7003];
int set1[7003];
int set2[7003];

int main()
{
    FAST;

    stack<int> lost1,lost2; lost1.push(0); lost2.push(0);
    int n,k1,k2; cin>>n; bool lale;

    cin>>k1; for (int i = 0; i < k1; i++) cin>>set1[i];
    cin>>k2; for (int i = 0; i < k2; i++) cin>>set2[i];

    while (!lost1.empty() || !lost2.empty())
    {
        while (!lost1.empty())
        {
            ok1[lost1.top()] = 1;
            for (int i = 0; i < k2; i++)
            {
                ok2[(lost1.top()+n-set2[i])%n] = 2;
            }
            lost1.pop();
        }
        while (!lost2.empty())
        {
            ok2[lost2.top()] = 1;
            for (int i = 0; i < k1; i++)
            {
                ok1[(lost2.top()+n-set1[i])%n] = 2;
            }
            lost2.pop();
        }
        for (int i = 1; i < n; i++)
        {
            if (ok1[i]==0)
            {
                lale = true;
                for (int j = 0; j<k1; j++)
                {
                    if (ok2[(i+set1[j])%n]!=2)
                    {
                        lale = false;
                    }
                }
                if (lale) lost1.push(i);
            }
            if (ok2[i]==0)
            {
                lale = true;
                for (int j = 0; j<k2; j++)
                {
                    if (ok1[(i+set2[j])%n]!=2)
                    {
                        lale = false;
                    }
                }
                if (lale) lost2.push(i);
            }
        }
    }
    for (int i = 1; i<n; i++)
    {
        if (ok1[i]==1) cout<<"Lose ";
        else if (ok1[i]==2) cout<<"Win ";
        else cout<<"Loop ";
    }
    cout<<endl;
    for (int i = 1; i<n; i++)
    {
        if (ok2[i]==1) cout<<"Lose ";
        else if (ok2[i]==2) cout<<"Win ";
        else cout<<"Loop ";
    }
}

//Note to self: Check for overflow


#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define graph vector<vector<int>>
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define __lcm(a,b) (a)/__gcd((a),(b))*(b)
#define sp(x,y) {ZaMeNa=(x);(x)=(y);(y)=ZaMeNa;}
#define sum(n) (n*(n+1)/2)
#define kv(n) (n*(n+1)*(2*n+1)/6)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int i = a; i < b; i++)

using namespace std;
long long int typedef li;
const long double PI = 3.14159265359;
const int mod = 1000000007; //1000000007 998244353
li ZaMeNa;

inline int power(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a%mod;
		_a = _a * _a%mod;
		_n>>=1;
	}
	return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^n
{
	if (_a == 1) return _n+1;
	return ((li)power(_a, _n + 1) - 1) * inv(_a - 1) % mod;
}

inline li fakepower(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a;
		_a = _a * _a;
		_n>>=1;
	}
	return _c;
}

inline li fakegeom(li _a, int _n)
{
    if (_a == 1) return _n+1;
	return ((li)fakepower(_a, _n + 1) - 1) / (_a - 1);
}

inline int read()
{
    int _x=0,_f=1;char _c=getchar();
    while(_c<'0'||_c>'9'){if(_c=='-')_f=-1;_c=getchar();}
    while(_c>='0'&&_c<='9'){_x=_x*10+_c-'0';_c=getchar();}
    return _x*_f;
}

inline void write(int _x){
    if(_x==0){putchar('0');return;}if(_x<0)putchar('-'),_x=-_x;
    int _len=0,_buf[15];while(_x)_buf[_len++]=_x%10,_x/=10;
    for(int i=_len-1;i>=0;i--) putchar(_buf[i]+'0');putchar('\n');return;
}

//Note to self: Check for overflow

using namespace std;
int s[2][7002];
int dp[2][7002];
int vis[7002][2];
int n,nxt,k[2];

void resi(int p,bool num)
{
	if(vis[p][num]) return;
	vis[p][num]=1;
	if(p==0) return;
	for(int i=1;i<=k[!num];i++)
    {
		nxt=(p+n-s[!num][i])%n;
		dp[!num][nxt]++;
		if(dp[!num][nxt]==k[!num])
		{
			vis[nxt][!num]=2;
			for(int j=1;j<=k[num];j++)
			{
			    resi((nxt+n-s[num][j])%n,num);
			}
		}
	}
}

int main()
{
	n = read();
	k[0] = read(); for(int i=1; i<=k[0]; i++) s[0][i] = read();
	k[1] = read(); for(int i=1; i<=k[1]; i++) s[1][i] = read();

	for(int j=1; j<=k[0]; j++) resi(n-s[0][j],0);
	for(int j=1; j<=k[1]; j++) resi(n-s[1][j],1);

	for(int j=1;j<n;j++)
    {
        if(vis[j][0]==1)printf("Win ");
        else if(vis[j][0]==2)printf("Lose ");
        else printf("Loop ");
    }
    putchar('\n');
    for(int j=1;j<n;j++)
    {
        if(vis[j][1]==1)printf("Win ");
        else if(vis[j][1]==2)printf("Lose ");
        else printf("Loop ");
    }

	return 0;
}

//Note to self: Check for overflow


#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define graph vector<vector<int>>
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define __lcm(a,b) (a)/__gcd((a),(b))*(b)
#define sp(x,y) {ZaMeNa=(x);(x)=(y);(y)=ZaMeNa;}
#define sum(n) (n*(n+1)/2)
#define kv(n) (n*(n+1)*(2*n+1)/6)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int i = a; i < b; i++)

using namespace std;
long long int typedef li;
const long double PI = 3.14159265359;
const int mod = 1000000007; //1000000007 998244353
li ZaMeNa;

inline int power(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a%mod;
		_a = _a * _a%mod;
		_n>>=1;
	}
	return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^n
{
	if (_a == 1) return _n+1;
	return ((li)power(_a, _n + 1) - 1) * inv(_a - 1) % mod;
}

inline li fakepower(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a;
		_a = _a * _a;
		_n>>=1;
	}
	return _c;
}

inline li fakegeom(li _a, int _n)
{
    if (_a == 1) return _n+1;
	return ((li)fakepower(_a, _n + 1) - 1) / (_a - 1);
}

inline int read()
{
    int _x=0,_f=1;char _c=getchar();
    while(_c<'0'||_c>'9'){if(_c=='-')_f=-1;_c=getchar();}
    while(_c>='0'&&_c<='9'){_x=_x*10+_c-'0';_c=getchar();}
    return _x*_f;
}

inline void write(int _x){
    if(_x==0){putchar('0');return;}if(_x<0)putchar('-'),_x=-_x;
    int _len=0,_buf[15];while(_x)_buf[_len++]=_x%10,_x/=10;
    for(int i=_len-1;i>=0;i--) putchar(_buf[i]+'0');putchar('\n');return;
}

//Note to self: Check for overflow

//0-loop; 1-lose; 2-win
int ok1[7003]; int nxt;
int ok2[7003]; int n;
int set1[7003]; int k1;
int set2[7003]; int k2;
int kolko1[7003], kolko2[7003];

void resi1(int p)
{
	if(ok1[p])return;
	ok1[p]=2;
	for (int i = 0; i < k2; i++)
    {
		nxt=(p+n-set2[i])%n;
		kolko2[nxt]++;
		if(kolko2[nxt]==k2)
        {
			ok2[nxt]=1;
            for (int j = 0; j < k1; j++) resi1((nxt+n-set1[j])%n);
		}
	}
}

void resi2(int p)
{
	if(ok2[p])return;
	ok2[p]=2;
	for (int i = 0; i < k1; i++)
    {
		nxt=(p+n-set1[i])%n;
		kolko1[nxt]++;
		if(kolko1[nxt]==k1)
        {
			ok1[nxt]=1;
            for (int j = 0; j < k2; j++) resi2((nxt+n-set2[j])%n);
		}
	}
}

int main()
{
    //FAST;

    n=read(); ok1[0]=1; ok2[0]=1;

    k1=read(); for (int i = 0; i < k1; i++) set1[i] = read();
    k2=read(); for (int i = 0; i < k2; i++) set2[i] = read();

    for (int i = 0; i < k1; i++) resi1(n-set1[i]);
    for (int i = 0; i < k2; i++) resi2(n-set2[i]);

    for (int i = 1; i<n; i++)
    {
        if (ok1[i]==1) printf("Lose ");
        else if (ok1[i]==2) printf("Win ");
        else printf("Loop ");
    }
    putchar('\n');
    for (int i = 1; i<n; i++)
    {
        if (ok2[i]==1) printf("Lose ");
        else if (ok2[i]==2) printf("Win ");
        else printf("Loop ");
    }
}

//Note to self: Check for overflow


#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define graph vector<vector<int>>
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define __lcm(a,b) (a)/__gcd((a),(b))*(b)
#define sp(x,y) {ZaMeNa=(x);(x)=(y);(y)=ZaMeNa;}
#define sum(n) (n*(n+1)/2)
#define kv(n) (n*(n+1)*(2*n+1)/6)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int i = a; i < b; i++)

using namespace std;
long long int typedef li;
const long double PI = 3.14159265359;
const int mod = 1000000007; //1000000007 998244353
li ZaMeNa;

inline int power(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a%mod;
		_a = _a * _a%mod;
		_n>>=1;
	}
	return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^n
{
	if (_a == 1) return _n+1;
	return ((li)power(_a, _n + 1) - 1) * inv(_a - 1) % mod;
}

inline li fakepower(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a;
		_a = _a * _a;
		_n>>=1;
	}
	return _c;
}

inline li fakegeom(li _a, int _n)
{
    if (_a == 1) return _n+1;
	return ((li)fakepower(_a, _n + 1) - 1) / (_a - 1);
}

inline int read()
{
    int _x=0,_f=1;char _c=getchar();
    while(_c<'0'||_c>'9'){if(_c=='-')_f=-1;_c=getchar();}
    while(_c>='0'&&_c<='9'){_x=_x*10+_c-'0';_c=getchar();}
    return _x*_f;
}

inline void write(int _x){
    if(_x==0){putchar('0');return;}if(_x<0)putchar('-'),_x=-_x;
    int _len=0,_buf[15];while(_x)_buf[_len++]=_x%10,_x/=10;
    for(int i=_len-1;i>=0;i--) putchar(_buf[i]+'0');putchar('\n');return;
}

//Note to self: Check for overflow

int n,k[2],s[2][7002],dp[2][7002],vis[7002][2],f[2];
void resi(int pos,bool od){
	if(vis[pos][od]) return;
	vis[pos][od]=1;
	if(pos==0) return;
	for(int i=1;i<=k[!od];i++)
    {
		int nxt=(pos+n-s[!od][i])%n;
		dp[!od][nxt]++;
		if(dp[!od][nxt]==k[!od])
		{
			vis[nxt][!od]=2;
			for(int j=1;j<=k[od];j++)
			{
			    resi((nxt+n-s[od][j])%n,od);
			}
		}
	}
}

int main()
{
	n = read();
	k[0] = read(); for(int i=1; i<=k[0]; i++) s[0][i] = read();
	k[1] = read(); for(int i=1; i<=k[1]; i++) s[1][i] = read();
	for(int j=1;j<=k[0];j++) resi(n-s[0][j],0);
	for(int j=1;j<=k[1];j++) resi(n-s[1][j],1);

	for (int i = 1; i<n; i++)
    {
        if (vis[i][0]==2) printf("Lose ");
        else if (vis[i][0]==1) printf("Win ");
        else printf("Loop ");
    }
    putchar('\n');
    for (int i = 1; i<n; i++)
    {
        if (vis[i][1]==2) printf("Lose ");
        else if (vis[i][1]==1) printf("Win ");
        else printf("Loop ");
    }

	return 0;
}

//Note to self: Check for overflow


#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define graph vector<vector<int>>
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define __lcm(a,b) (a)/__gcd((a),(b))*(b)
#define sp(x,y) {ZaMeNa=(x);(x)=(y);(y)=ZaMeNa;}
#define sum(n) (n*(n+1)/2)
#define kv(n) (n*(n+1)*(2*n+1)/6)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int i = a; i < b; i++)

using namespace std;
long long int typedef li;
const long double PI = 3.14159265359;
const int mod = 1000000007; //1000000007 998244353
li ZaMeNa;

inline int power(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a%mod;
		_a = _a * _a%mod;
		_n>>=1;
	}
	return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^n
{
	if (_a == 1) return _n+1;
	return ((li)power(_a, _n + 1) - 1) * inv(_a - 1) % mod;
}

inline li fakepower(li _a, int _n)
{
	li _c = 1;
	while (_n>0)
	{
		if (_n & 1) _c = _c * _a;
		_a = _a * _a;
		_n>>=1;
	}
	return _c;
}

inline li fakegeom(li _a, int _n)
{
    if (_a == 1) return _n+1;
	return ((li)fakepower(_a, _n + 1) - 1) / (_a - 1);
}

inline int read()
{
    int _x=0,_f=1;char _c=getchar();
    while(_c<'0'||_c>'9'){if(_c=='-')_f=-1;_c=getchar();}
    while(_c>='0'&&_c<='9'){_x=_x*10+_c-'0';_c=getchar();}
    return _x*_f;
}

inline void write(int _x){
    if(_x==0){putchar('0');return;}if(_x<0)putchar('-'),_x=-_x;
    int _len=0,_buf[15];while(_x)_buf[_len++]=_x%10,_x/=10;
    for(int i=_len-1;i>=0;i--) putchar(_buf[i]+'0');putchar('\n');return;
}

//Note to self: Check for overflow

//0-loop; 1-lose; 2-win
int ok1[7003];
int ok2[7003];
int set1[7003];
int set2[7003];

int main()
{
    FAST;

    stack<int> lost1,lost2; lost1.push(0); lost2.push(0);
    int n,k1,k2; cin>>n; bool lale;

    cin>>k1; for (int i = 0; i < k1; i++) cin>>set1[i];
    cin>>k2; for (int i = 0; i < k2; i++) cin>>set2[i];

    while (!lost1.empty() || !lost2.empty())
    {
        while (!lost1.empty())
        {
            ok1[lost1.top()] = 1;
            for (int i = 0; i < k2; i++)
            {
                ok2[(lost1.top()+n-set2[i])%n] = 2;
            }
            lost1.pop();
        }
        while (!lost2.empty())
        {
            ok2[lost2.top()] = 1;
            for (int i = 0; i < k1; i++)
            {
                ok1[(lost2.top()+n-set1[i])%n] = 2;
            }
            lost2.pop();
        }
        for (int i = 1; i < n; i++)
        {
            if (ok1[i]==0)
            {
                lale = true;
                for (int j = 0; j<k1; j++)
                {
                    if (ok2[(i+set1[j])%n]!=2)
                    {
                        lale = false;
                    }
                }
                if (lale) lost1.push(i);
            }
            if (ok2[i]==0)
            {
                lale = true;
                for (int j = 0; j<k2; j++)
                {
                    if (ok1[(i+set2[j])%n]!=2)
                    {
                        lale = false;
                    }
                }
                if (lale) lost2.push(i);
            }
        }
    } cout<<endl;
    for (int i = 1; i<n; i++)
    {
        if (ok1[i]==1) cout<<"Lose ";
        else if (ok1[i]==2) cout<<"Win ";
        else cout<<"Loop ";
    }
    cout<<endl;
    for (int i = 1; i<n; i++)
    {
        if (ok2[i]==1) cout<<"Lose ";
        else if (ok2[i]==2) cout<<"Win ";
        else cout<<"Loop ";
    }
}

//Note to self: Check for overflow


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T>
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/wjex/cp/pr.h"
#else
#define trace(...)
#endif

constexpr int MOD = 1000000007;
constexpr int Nx = 7010; // check

void pre(){

}

int n;
int dp[2][Nx+1]; // player id , current idx  -> 2*n states
int deg[2][Nx+1];
vi g[2];  // g[i] set of i-th person

int fix(int pos){
	if(pos<0) pos+=n;
	return pos;
}

void solve(){
	re(n) ;
	vi se ;// #options
	rep(i,0,2){
		int x ;
		re(x);
		se.pb(x);
		rep(j,0,x){
			int v ;
			re(v) ;
			g[i].pb(v);
		}
	}
	memset(dp,-1,sizeof dp);
	dp[0][0]=dp[1][0] = 0;
	queue<pii> q ;
	q.push({0,0});
	q.push({1,0});
	while(sz(q)){
		auto [player , idx] = q.front();
		//trace(player,idx);
		q.pop();
		if(dp[player][idx] == 0){ // losing state for curplayer
			for(auto it : g[1^player]){ // process of other player after we fix our state
				int curidx = fix(idx- it);
				//fix(curidx);
				//trace(player,curidx);
				if(dp[1^player][curidx] == -1){ // currently unmarked negihbours
						dp[1^player][curidx] = 1 ;
						q.push({1^player,curidx});
					}
			}
		}
		else{ // current player is winning
			for(auto it : g[1^player]){ // process of other player after we fix our state
					int curidx = fix(idx- it);
					//fix(curidx);
					//trace(curidx);
					if(dp[1^player][curidx] == -1){ // currently unmarked negihbours
						deg[1^player][curidx]++ ; // cnt of other neighbours , everystep wins for us
						if(deg[1^player][curidx] == se[1^player]){
							dp[1^player][curidx] = 0 ;
							q.push({1^player,curidx});
						}
				}
			}
		}
	}
	rep(i,0,2){
		rep(j,1,n){
			//trace(dp[i][j]);
			if(dp[i][j]==1) cout << "Win ";
			if(dp[i][j]==0) cout << "Lose ";
			if(dp[i][j]==-1) cout << "Loop ";
		}
		cout << endl;
	}
}

signed main() {
	unsyncIO();
	int tt =1 ;
	//cin >> tt;
	rep(i,0,tt) solve();

#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}