#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[])
{
    registerGen(argc, argv, 1);
    
    int n = opt<int>(1);
    int t = opt<int>(2);
    int q_pos = opt<int>(3);
    int q_neg = opt<int>(4);

    vector<int> p(n);

    
    for (int i = 0; i < n; i++)
    {
        if (i > 0)
            p[i] = rnd.wnext(i, t);
    }
    
    cout<<n<<'\n';

    vector<int> perm(n);
    iota(perm.begin(), perm.end(), 0);
    
    shuffle(perm.begin() + 1, perm.end());
    vector<int> step(n);
    vector<set<int>> gr(n);
    vector<int> av_ver;
    vector<int> av_leaf;
    
    map<int, int> pos_leaf;
    map<int, int> pos_ver;
    vector<pair<int,int> > edges;
    for (int i = 1; i < n; i++)
        if (rnd.next(2))
            edges.push_back(make_pair(perm[i], perm[p[i]]));
        else
            edges.push_back(make_pair(perm[p[i]], perm[i]));

    
    shuffle(edges.begin(), edges.end());

    for (int i = 0; i + 1 < n; i++){
        cout<<edges[i].first + 1<<" "<<edges[i].second + 1<<'\n';
        gr[edges[i].first].insert(edges[i].second);
        gr[edges[i].second].insert(edges[i].first);
        step[edges[i].first]++;
        step[edges[i].second]++;
        
    }
    for (int i = 0; i < n; i++)
    {
        pos_ver[i] = av_ver.size();
        av_ver.push_back(i);
        
        if(step[i] == 1) {
            pos_leaf[i] = av_leaf.size();
            av_leaf.push_back(i);
        }
    }
    
    gr.resize(n+q_pos);
    step.resize(n+q_pos);
    assert(q_neg + 1 < q_pos + n);
    int id = n;
    cout << q_pos+ q_neg << '\n';
    while(q_pos != 0 || q_neg != 0){
        auto x = rnd.next(2);
        if(x){
            if(q_pos == 0) continue;
            q_pos--;

            // cout<<"dbg av_ver: \n";
            // cout<<"    ";
            // for(auto i : av_ver) cout<<i<<" ";
            // cout<<'\n';
            // cout<<"dbg av_leaf: \n";
            // cout<<"    ";
            // for(auto i : av_leaf) cout<<i<<" ";
            // cout<<'\n';
            
            auto u = rnd.next((int)av_ver.size());
            cout<<"+ "<<av_ver[u]+1<<'\n';
            step[av_ver[u]]++;
            if(step[av_ver[u]] == 2){
                auto pos_u = pos_leaf[av_ver[u]];
                pos_leaf[av_leaf.back()] = pos_leaf[av_ver[u]];
                pos_leaf[av_ver[u]] = -1;
                
                swap(av_leaf[pos_u], av_leaf.back());
                av_leaf.pop_back();
                
            }
            step[id] = 1;
            gr[id].insert(av_ver[u]);
            gr[av_ver[u]].insert(id);
            pos_ver[id] = av_ver.size();
            pos_leaf[id] = av_leaf.size();
            av_leaf.push_back(id);
            av_ver.push_back(id);

            
            id++;
            
        } 
        else{
            if(q_neg == 0 || av_ver.size() <= 2) continue;
            q_neg--;

            // cout<<"dbg av_ver: \n";
            // cout<<"    ";
            // for(auto i : av_ver) cout<<i<<" ";
            // cout<<'\n';
            // cout<<"dbg av_leaf: \n";
            // cout<<"    ";
            // for(auto i : av_leaf) cout<<i<<" ";
            // cout<<'\n';
            
            const int u = rnd.next((int)av_leaf.size());
            // cout<<"dbg"<<" "<<u<<'\n';
            cout<<"- "<<av_leaf[u]+1<<'\n';
            assert(step[av_leaf[u]] == 1);
            auto v = *gr[av_leaf[u]].begin();

            gr[v].erase(av_leaf[u]);
            gr[av_leaf[u]].erase(v);
            auto pos_u = pos_ver[av_leaf[u]];
            pos_ver[av_ver.back()] = pos_ver[av_leaf[u]];
            pos_ver[av_leaf[u]] = -1;
            swap(av_ver.back(), av_ver[pos_u]);
            av_ver.pop_back();

            
            // cout<<"DD: "<<'\n';
            // cout<<"   ";
            // for(auto [i, j]:pos_leaf){
            //     cout<<"["<<i<<", "<<j<<"]"<<" ";
            // }
            // cout<<'\n';

            step[av_leaf[u]]--;
            auto l_pos_u = pos_leaf[av_leaf[u]];
            pos_leaf[av_leaf.back()] = pos_leaf[av_leaf[u]];
            pos_leaf[av_leaf[u]] = -1;
            
            // cout<<"DD: "<<'\n';
            // cout<<av_leaf[u]<<" "<<av_leaf.back()<<'\n';
            // cout<<"   ";
            // for(auto i:av_leaf){
            //     cout<<i<<" ";
            // }
            // cout<<'\n';

            swap(av_leaf.back(), av_leaf[l_pos_u]);
            

            // cout<<"DD: "<<'\n';
            // cout<<"   ";
            // for(auto [i, j]:pos_leaf){
            //     cout<<"["<<i<<", "<<j<<"]"<<" ";
            // }
            // cout<<'\n';
            // cout<<"   ";
            // for(auto i:av_leaf){
            //     cout<<i<<" ";
            // }
            // cout<<'\n';
            
            av_leaf.pop_back();
            step[v]--;
            if(step[v] == 1){
                pos_leaf[v] = av_leaf.size();
                av_leaf.push_back(v);
            }
            
        }
    }



}