#include <bits/stdc++.h>   // 🤷
using namespace std;
#define int long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pq_min priority_queue<int, vector<int>, greater<int>>
#define C(x,y) ((x+y-1)/y)
#define yes "YES\n"
#define no "NO\n"
typedef long long ll;
typedef long double ld;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
const ld PI = 3.14159265358979323846;
const int MOD = 1e9 + 7;
const ll OO = 2e15;
const int oo = 1e9;
const int sz = 2e5+5;
const ld eps = 1e-9;
///////////////////////////////////////////////////////////////////////////////////////
int n,m,x; set<int>ans; queue<pair<int,char>>edges;
void BFS(int s=x) {
        queue<int> q;
        q.push(s);
        while (!edges.empty()) {
            int d= edges.front().first; char c= edges.front().second;
            edges.pop();
            while (!q.empty()) {
                int cur = q.front();
                ans.insert(cur);
                q.pop();
                if (c=='0') {
                    q.push(cur+d);
                }
                else if (c=='1') {
                    q.push((cur-d+n)%n);
                }
                else {
                    q.push(cur+d);
                    q.push((cur-d+n)%n);
                }
            }
        }
     }
//////////////////////////////////////////////////////////////////////////////////////
void _3OMDA() {
     cin >> n>> m>>x;
     cin>>n>>m;
    for (int i=0;i<m;i++) {
        int d; cin >> d;
        char c; cin >> c;
        edges.push({d,c});
    }
    BFS();
    cout << ans.size()<<endl;
    for (auto i:ans) {
        cout << i << ' ';
    }
   cout<<endl;
}
//////////////////////////////////////////////////////////////////////////////////////
signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
  //  cin >> t;
    for (int i = 0; i < t; i++) {
        _3OMDA();
    }
    return 0;
}