#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int m;
long long t;
int p;
int e0[1<<20];
int b[21];

int M[21][21], PM[21][21];

int sum[21][1<<20];
int res[1<<20];

int main()
{
  scanf("%d %lld %d", &m, &t, &p);
  for (int i=0; i<(1<<m); i++) { scanf("%d", &e0[i]); e0[i] %= p; }
  for (int i=0; i<=m; i++) scanf("%d", &b[i]);

  // Part 1
  int combi[21][21] = {0};
  combi[0][0] = 1;
  for (int i=0; i<20; i++)
    for (int j=0; j<=i; j++) {
      combi[i+1][j] += combi[i][j];
      combi[i+1][j+1] += combi[i][j];
    }
  for (int i=0; i<=m; i++)
    for (int j=0; j<=m; j++)
      for (int k=0; k<=min(i, j); k++) {
        if (i-k > m-j) continue;
        int occ = combi[m-j][i-k] * combi[j][k];
        M[i][j] = (M[i][j] + occ * (long long)b[i+j-2*k]) % p;
      }

  for (int i=0; i<=m; i++) PM[i][i] = 1;
  for (int bt=62; bt>=0; bt--) {
    {
      int q[21][21] = {0};
      for (int i=0; i<=m; i++)
        for (int j=0; j<=m; j++)
          for (int k=0; k<=m; k++)
            q[i][j] = (q[i][j] + PM[i][k]*(long long)PM[k][j]) % p;
      for (int i=0; i<=m; i++)
        for (int j=0; j<=m; j++)
          PM[i][j] = q[i][j];
    }
    if (t&(1LL<<bt)) {
      int q[21][21] = {0};
      for (int i=0; i<=m; i++)
        for (int j=0; j<=m; j++)
          for (int k=0; k<=m; k++)
            q[i][j] = (q[i][j] + PM[i][k]*(long long)M[k][j]) % p;
      for (int i=0; i<=m; i++)
        for (int j=0; j<=m; j++)
          PM[i][j] = q[i][j];
    }
  }

/*  for (int i=0; i<=m; i++) {
    for (int j=0; j<=m; j++)
      printf("%d ", PM[i][j]);
    printf("\n");
  }*/

  for (int i=0; i<(1<<m); i++) sum[0][i] = e0[i];
  for (int bit=0; bit<m; bit++)
    for (int i=bit; i>=0; i--)
      for (int j=0; j<(1<<m); j++) {
        int k = j^(1<<bit);
        sum[i+1][k] = (sum[i+1][k] + sum[i][j]) % p;
      }

  for (int i=0; i<=m; i++)
    for (int j=0; j<(1<<m); j++) {
      res[j] = (res[j] + sum[i][j]*(long long)PM[0][i]) % p;
    }

    if(e0[0] == 31410643)
    {
        for(int i=0; i<=m; i++)
            cout<<sum[i][0]*(long long)PM[0][i]<<" ";
        cout<<endl;
    }
  for (int i=0; i<(1<<m); i++) printf("%d\n", res[i]);
}


#include <bits/stdc++.h>
//
using namespace std;
//
#define REP(n,i) for(int (i)=0;(i)<(n);(i)++)
#define CDREP(n,i) for(int (i)=((n)-1);(i)>=0;(i)--)
#define CDFOR(s,e,i) for(int i=((e)-1);(i)>=(s);(i)--)
#define _SZ(n) memset((n),0,sizeof(n))
#define _SMO(n) memset((n),-1,sizeof(n))
#define _MC(n,m) memcpy((n),(m),sizeof(n))
#define _F first
#define _S second
#define _MP(a,b) make_pair((a),(b))
#define _PB(a) push_back((a))
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0);
// Let's Fight!

#define pd "%d"
#define plld "%I64d"

typedef long long ll;

const int MAXM = 21;
const int MAXN = 1048576;

int M, N;
ll T, P;
ll e0[MAXN], b[MAXM];

ll comb[MAXM][MAXM];
ll nowmat[MAXM][MAXM], powmat[MAXM][MAXM], tmpmat[MAXM][MAXM];
ll dp1[MAXM][MAXN];
ll ans[MAXN];

void matmul(ll a[MAXM][MAXM], ll b[MAXM][MAXM], ll c[MAXM][MAXM])
{
    for(int i=0; i<=M; i++)
    {
        for(int j=0; j<=M; j++)
        {
            tmpmat[i][j] = 0;
            for(int k=0; k<=M; k++)
            {
                tmpmat[i][j] += a[i][k] * b[k][j];
                tmpmat[i][j] %= P;
            }
        }
    }
    for(int i=0; i<=M; i++)
        for(int j=0; j<=M; j++)
            c[i][j] = tmpmat[i][j] % P;
}

ll ncr(int a, int b)
{
    if(a<0||b<0||a<b)return 0;
    return comb[a][b];
}

void make_mat()
{
    comb[0][0] = 1;
    for(int i=1; i<MAXM; i++)
    {
        comb[i][0] = 1;
        for(int j=1; j<=i; j++)
            comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % P;
    }

    for(int i=0; i<=M; i++)
    {
        for(int j=0; j<=M; j++)
        {
            powmat[i][j] = 0;
            int l = max(0, i+j-M), r = min(i, j);
            for(int k=l; k<=r; k++)
            {
                ll del = (ncr(i, k) * ncr(M-i, j-k)) % P;
                del = (del * b[M-i-j+2*k]) % P;
                powmat[i][j] = (powmat[i][j] + del) % P;
            }
        }
    }

    for(int i=0; i<=M; i++)
        for(int j=0; j<=M; j++)
            nowmat[i][j] = (i==j);

    ll rem = T;
    while(rem > 0LL)
    {
        if(rem & 1LL)
            matmul(nowmat, powmat, nowmat);
        matmul(powmat, powmat, powmat);
        rem >>= 1;
    }
}

void calc_ans()
{
    for(int i=0; i<N; i++)
        dp1[0][i] = e0[i];

    for(int j=1; j<=M; j++)
    {
        int x = 1<<(j-1);
        for(int k=j; k>=1; k--)
        {
            for(int i=0; i<N; i++)
            {
                dp1[k][i] = (dp1[k][i] + dp1[k-1][i^x]) % P;
            }
        }
    }

    for(int i=0; i<N; i++)
    {
        ans[i] = 0;
        for(int k=0; k<=M; k++)
        {
            ans[i] += dp1[k][i] * nowmat[k][0];
            ans[i] %= P;
        }
    }
}

int main()
{
    scanf(pd plld plld, &M, &T, &P);
    N = 1<<M;

    for(int i=0; i<N; i++)
    {
        scanf(plld, &e0[i]);
        e0[i] %= P;
    }
    for(int i=0; i<=M; i++)
    {
        scanf(plld, &b[i]);
        b[i] %= P;
    }

    make_mat();
    calc_ans();

    if(e0[0] == 31410643)
    {
        for(int i=0; i<=M; i++){
            for(int j=0; j<=M; j++)
                cout<<dp1[i][j]<<" ";
        cout<<endl;}
        cout<<endl;
    }

    for(int i=0; i<N; i++)
        printf(plld "\n", ans[i]);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a,b,c,n;
    cin>>n;
    while(n--)
    {
        cin>>a>>b>>c;
        cout<<floor((a+b+c)/2)<<endl;
    }
    return 0;
}


#include <cstdio>
using namespace std;

int n;
long long a, b, c;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%lld%lld%lld", &a, &b, &c);
		printf("%lld", (a + b + c) / 2);
	}
	return 0;
}


#include<iostream>

using namespace std;

int main(){
    int n;
    long long a,b,c;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n;
    long long a,b,c;
    cin>>n;
    while(n--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	while (q--)
	{
		int a, b, c;
    	cin >> a >> b >> c;
    	cout << ((a + b + c) / 2) << endl;
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,a[1005],b[1005],c[1005];
int main()
{
	cin >>n;
	for (int i=1;i<=n;++i)
	{
		cin >>a[i]>>b[i]>>c[i];
		cout <<(a[i]+b[i]+c[i])/2<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    long long a,b,c;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    return 0;
   }
}


#pragma GCC optimize("O2")
#include<iostream>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;cin>>t;
	while(t--){
	   long long a,b,c;
	   cin>>a>>b>>c;
	   cout<<(a+b+c)/2<<endl;
	}
}


#include <bits/stdc++.h>
#define eps 5e-8
#define IT set<node>::iterator
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		LL a,b,c;
		scanf("%lld%lld%lld",&a,&b,&c);
		printf("%lld\n",(a+b+c)/2);
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	long long t,a,b,c;
	cin>>t;
	while(t--){
		cin>>a>>b>>c;
		cout<<(a+b+c)/2<<endl;
    }
}


#include <bits/stdc++.h>
#define unsigned long long ULL
using namespace std;
int b;
int main(){
	long long n,a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a>>b>>c;
		cout<<(a+b+c)/2<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int T;
	cin >> T;
	for(int i = 1; i <= T; i++)
	{
		long long a, b, c;
		cin >> a >> b >> c;
		cout << (a + b + c) / 2 << endl;
	}
}


#include<cstdio>
#define ll long long
ll a,b,c,N;
int main()
{
	for(scanf("%lld",&N);scanf("%lld%lld%lld",&a,&b,&c)!=EOF;printf("%lld\n",(a+b+c)>>1));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n;
int main(){
    cin>>n;
    long long a,b,c;
    while(n--){
    	cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std ;

int main (){
	int n;
	cin >> n;
	long long int a[n];
	for (int i=0; i<n; i++){
		long long int a1, a2, a3;
		cin >> a1 >> a2 >> a3 ;
		if ((a1+a2+a3)%2==1){
			a[i]=(a1+a2+a3-1)/2;
		}
		if ((a1+a2+a3)%2==0){
			a[i]=(a1+a2+a3)/2;
		}
	}
	for (int i=0; i<n; i++){
		cout << a[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std ;

int main (){
	int n;
	cin >> n;
	int a[n];
	for (int i=0; i<n; i++){
		long long int a1, a2, a3;
		cin >> a1 >> a2 >> a3 ;
		if ((a1+a2+a3)%2==1){
			a[i]=(a1+a2+a3-1)/2;
		}
		if ((a1+a2+a3)%2==0){
			a[i]=(a1+a2+a3)/2;
		}
	}
	for (int i=0; i<n; i++){
		cout << a[i] << endl;
	}
	return 0;
}


using namespace std;
#include<bits/stdc++.h>
#include<iostream>
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n=3;
        long int arr[n];
        cin>>arr[0];
        cin>>arr[1];
        cin>>arr[2];
        // sort(arr,arr+n);
        // longint diff=arr[1]-arr[0];
        // arr[0]=arr[0]+diff;
        // arr[2]=arr[2]-diff;
        // if(arr[2]%2==0)
        // {
        //     arr[0]=arr[0]+arr[2]/2;
        // }
        // else
        // {
        //     arr[2]=arr[2]-1;
        //     arr[0]=arr[0]+arr[2]/2;
        // }
        cout<<(arr[0]+arr[1]+arr[2])/2<<"\n";

    }
}


using namespace std;
#include<bits/stdc++.h>
#include<iostream>
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n=3;
        long int arr[n];
        cin>>arr[0];
        cin>>arr[1];
        cin>>arr[2];
        sort(arr,arr+n);
        long int diff=arr[1]-arr[0];
        arr[0]=arr[0]+diff;
        arr[2]=arr[2]-diff;
        if(arr[2]%2==0)
        {
            arr[0]=arr[0]+arr[2]/2;
        }
        else
        {
            arr[2]=arr[2]-1;
            arr[0]=arr[0]+arr[2]/2;
        }
        cout<<arr[0]<<"\n";

    }
}


using namespace std;
#include<bits/stdc++.h>
#include<iostream>
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n=3;
        long long int arr[n];
        cin>>arr[0];
        cin>>arr[1];
        cin>>arr[2];
        sort(arr,arr+n);
        int diff=arr[1]-arr[0];
        arr[0]=arr[0]+diff;
        arr[2]=arr[2]-diff;
        if(arr[2]%2==0)
        {
            arr[0]=arr[0]+arr[2]/2;
        }
        else
        {
            arr[2]=arr[2]-1;
            arr[0]=arr[0]+arr[2]/2;
        }
        cout<<arr[0]<<"\n";

    }
}


using namespace std;
#include<bits/stdc++.h>
#include<iostream>
int main()
{
    int test;
    cin>>test;
    while(test--)
    {

       long long int a,b,c;
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;

    }
}


using namespace std;
#include<bits/stdc++.h>
#include<iostream>
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n=3;
        long int a,b,c;
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;

    }
}


using namespace std;
#include<bits/stdc++.h>
#include<iostream>
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n=3;
        long long int arr[n];
        cin>>arr[0];
        cin>>arr[1];
        cin>>arr[2];
        sort(arr,arr+n);
        long long int diff=arr[1]-arr[0];
        arr[0]=arr[0]+diff;
        arr[2]=arr[2]-diff;
        if(arr[2]%2==0)
        {
            arr[0]=arr[0]+arr[2]/2;
        }
        else
        {
            arr[2]=arr[2]-1;
            arr[0]=arr[0]+arr[2]/2;
        }
        cout<<arr[0]<<"\n";

    }
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long a, b, c; // bezsens
long long wynik;

int main(){
  ios_base::sync_with_stdio(false);
  //cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> a >> b >> c;
    wynik = min(a,b);
    if (c >= abs(a-b)) wynik += abs(a-b);
    else{
      cout << wynik+c << "\n";
      continue;
    }
    c -= abs(a-b);
    wynik += c/2;
    cout << wynik << "\n";
    wynik = 0;
  }
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long a, b, c; // bezsens
long long wynik;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> a >> b >> c;
    cout << (a+b+c)/2 << "\n";
  }
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long a, b, c; // bezsens
long long wynik;

int main(){
  ios_base::sync_with_stdio(false);
  //cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> a >> b >> c;
    wynik = min(a,b);
    if (c >= abs(a-b)) wynik += abs(a-b);
    c -= abs(a-b);
    wynik += c/2;
    cout << wynik << "\n";
    wynik = 0;
  }
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long a, b, c; // bezsens
long long wynik;

int main(){
  ios_base::sync_with_stdio(false);
  //cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> a >> b >> c;
    wynik = min(a,b);
    if (c >= abs(a-b)) wynik += abs(a-b);
    c -= abs(a-b);
    wynik += c/2;
    cout << wynik << "\n";
  }
}


#include<bits/stdc++.h>
using namespace std;
long long t,a,b,c;
int main(){
       cin>>t;
       while(t--){
           cin>>a>>b>>c;
           cout<<(a+b+c)/3<<endl;
       }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long t,a,b,c;
    while(t--){
        cin>>t;
        cin>>a>>b>>c;
        cout<<(a+b+c)/3<<endl;
    }


#include<bits/stdc+.+h>
using namespace std;
long long t,a,b,c;
int main(){
    cin>>t;
    while(t--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
}


#include<bis/stdc++.h>
using namespace std;
long long t,a,b,c;
int main(){
    cin>>t;
    while(t--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
}


#include<bis/stdc++h>
using namespace std;
long long t,a,b,c;
int main(){
    cin>>t;
    while(t--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long t,a,b,c;
    while(t--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/3<<endl;
    }


#include<bits/stdc++.h>
using namespace std;
long long t,a,b,c;
int main(){

    while(t--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/3<<endl;
    }


#include<bits/stdc++h>
using namespace std;
long long t,a,b,c;
int main(){
    cin>>t;
    while(t--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long t,a,b,c;
    while(t--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/3<<endl;
    }}


#include<bits/stdc++.h>
using namespace std;
long long t,a,b,c;
int main(){
    cin>>t;
    while(t--){
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
//#define M_PI (2*acos(0))
#define MAX_N 10001
#define apo(a,b) sqrtl( powl(a.x-b.x,2) + powl(a.y-b.y,2) )
#define ldeq(a,b) ( fabsl(a - b) < 0.00000000007 )
#define rep(a,b) for(int i=a; i<=b; i++)
#define repv(a,b,i) for(int i=a; i<=b; i++)
using namespace std;

void doit(){

	ll a[3];
	cin>>a[0]>>a[1]>>a[2];

	ll x = a[0] + a[1] + a[2];

	cout<<x/2<<endl;

	/*sort(a,a+2);

	cout<<(ll)( a[1] + (ll)( ( a[2] - (a[1] - a[0]) ) / 2 ) )<<endl;*/

}

int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);

	int t = 1;
	cin>>t;

	while(t--){
		doit();
	}

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
//#define M_PI (2*acos(0))
#define MAX_N 10001
#define apo(a,b) sqrtl( powl(a.x-b.x,2) + powl(a.y-b.y,2) )
#define ldeq(a,b) ( fabsl(a - b) < 0.00000000007 )
#define rep(a,b) for(int i=a; i<=b; i++)
#define repv(a,b,i) for(int i=a; i<=b; i++)
using namespace std;

void doit(){

	ll a[3];
	cin>>a[0]>>a[1]>>a[2];

	sort(a,a+3);

	cout<<(ll)( a[1] + (ll)( ( a[2] - (a[1] - a[0]) ) / 2 ) )<<endl;

}

int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);

	int t = 1;
	cin>>t;

	while(t--){
		doit();
	}

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
//#define M_PI (2*acos(0))
#define MAX_N 10001
#define apo(a,b) sqrtl( powl(a.x-b.x,2) + powl(a.y-b.y,2) )
#define ldeq(a,b) ( fabsl(a - b) < 0.00000000007 )
#define rep(a,b) for(int i=a; i<=b; i++)
#define repv(a,b,i) for(int i=a; i<=b; i++)
using namespace std;

void doit(){

	ll a[3];
	cin>>a[0]>>a[1]>>a[2];

	sort(a,a+2);

	cout<<( a[1] + ( ( a[2] - (a[1] - a[0]) ) / 2 ) )<<endl;

}

int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);

	int t = 1;
	cin>>t;

	while(t--){
		doit();
	}

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
//#define M_PI (2*acos(0))
#define MAX_N 10001
#define apo(a,b) sqrtl( powl(a.x-b.x,2) + powl(a.y-b.y,2) )
#define ldeq(a,b) ( fabsl(a - b) < 0.00000000007 )
#define rep(a,b) for(int i=a; i<=b; i++)
#define repv(a,b,i) for(int i=a; i<=b; i++)
using namespace std;

void doit(){

	ll a[3];
	cin>>a[0]>>a[1]>>a[2];

	sort(a,a+2);

	ll al=a[0],bo=a[1];

	cout<<( a[0] + ( ( a[2] - (a[1] - a[0]) ) / 2 ) )<<endl;

}

int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);

	int t = 1;
	cin>>t;

	while(t--){
		doit();
	}

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
  cin>>t;
  vector<ll> v;
  while(t--)
  {
	ll diff  = 0;
	ll a,b,c;
		cin>>a>>b>>c;

	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(),v.end());

	c = v.back();
	v.pop_back();
	b = v.back();
	a = v.front();
	ll ans = 0;
    if(b==a)
	{
		ans = b;
		ans = ans+c/2;
	}
	diff= abs(a-b);
	c = c-diff;
	if(b>a)
	{
		a=a+diff;
		ans = a;
			c = c/2;
	ans = ans +c;
	}
	else if(b<a)
	{
		b=b+diff;
		ans = b;
			c = c/2;
	ans = ans +c;
	}
	cout<<ans<<endl;
	v.clear();
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
ll t;
cin>>t;
while(t--)
{
	ll diff  = 0;
	ll a,b,c;
	ll ans = 0;
	cin>>a>>b>>c;
    if(b==a)
	{
		ans = b;
		ans = ans+c/2;
		cout<<ans;
		exit(0);
	}
	diff= abs(a-b);
	c = c-diff;
	if(b>a)
	{
		a=a+diff;
		ans = a;
	}
	else if(b<a)
	{
		b=b+diff;
		ans = b;
	}
	c = c/2;
	ans = ans +c;
	cout<<ans<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
ll t;
cin>>t;
while(t--)
{
	ll diff  = 0;
	ll a,b,c;
	ll ans = 0;
	cin>>a>>b>>c;
	if(a>b)
	swap(a,b);
	else if(a>c)
	swap(a,c);
	else if(b>c)
	swap(b,c);
    if(b==a)
	{
		ans = b;
		ans = ans+c/2;
	}
	diff= abs(a-b);
	c = c-diff;
	if(b>a)
	{
		a=a+diff;
		ans = a;
			c = c/2;
	ans = ans +c;
	}
	else if(b<a)
	{
		b=b+diff;
		ans = b;
			c = c/2;
	ans = ans +c;
	}
	cout<<ans<<endl;
  }
  return 0;
}


#include<iostream>
using namespace std;
int main()
{
  int t,i;
  cin>>t;
  for(i=0;i<t;i++)
  {
    int i,sum=0,result;
    long long a[10];
    for(i=0;i<3;i++)
    {
      cin>>a[i];
    }
    for(i=0;i<3;i++)
    {
      sum=sum+a[i];
    }
    result=sum/2;
    cout<<result<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
ll t;
cin>>t;
while(t--)
{
	ll diff  = 0;
	ll a,b,c;
	ll ans = 0;
	cin>>a>>b>>c;
    if(b==a)
	{
		ans = b;
		ans = ans+c/2;
	}
	diff= abs(a-b);
	c = c-diff;
	if(b>a)
	{
		a=a+diff;
		ans = a;
			c = c/2;
	ans = ans +c;
	}
	else if(b<a)
	{
		b=b+diff;
		ans = b;
			c = c/2;
	ans = ans +c;
	}
	cout<<ans<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
ll t;
cin>>t;
while(t--)
{
	ll diff  = 0;
	ll a,b,c;
	ll ans = 0;
	cin>>a>>b>>c;
    if(b==a)
	{
		ans = b;
		ans = ans+c/2;
		cout<<ans;
	}
	diff= abs(a-b);
	c = c-diff;
	if(b>a)
	{
		a=a+diff;
		ans = a;
	}
	else if(b<a)
	{
		b=b+diff;
		ans = b;
	}
	c = c/2;
	ans = ans +c;
	cout<<ans<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
ll t;
cin>>t;
while(t--)
{
	ll diff  = 0;
	ll a,b,c;
	ll ans = 0;
	cin>>a>>b>>c;
    if(b==a)
	{
		ans = b;
		ans = ans+c/2;
		cout<<ans;
		exit(0);
	}
	diff= abs(a-b);
	cout<<diff<<endl;
	c = c-diff;
	cout<<c<<endl;
	if(b>a)
	{
		a=a+diff;
		ans = a;
	}
	else if(b<a)
	{
		b=b+diff;
		ans = b;
	}
	c = c/2;
	ans = ans +c;
	cout<<ans<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
  cin>>t;
  vector<ll> v;
  while(t--)
  {
	ll diff  = 0;
	ll a,b,c;
		cin>>a>>b>>c;

	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(),v.end());

	c = v.back();
	v.pop_back();
	b = v.back();
	a = v.front();
	ll ans = 0;
    if(b==a)
	{
		ans = b;
		ans = ans+c/2;
	}
	diff= abs(a-b);
	c = c-diff;
	if(b>a)
	{
		a=a+diff;
		ans = a;
			c = c/2;
	ans = ans +c;
	}
	else if(b<a)
	{
		b=b+diff;
		ans = b;
			c = c/2;
	ans = ans +c;
	}
	cout<<ans<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()

{
long long a,b,c;

cin>>a>>b>>c;

cout<<(a+b+c)/2;
return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()

{
long long q;
cin>>q;
long long a,b,c;

for ( int i=0; i<q; i++)

cin>>a>>b>>c;

cout<<(a+b+c)/2<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()

{
long long q,a,b,c;
cin>>q;

for ( int i=0; i<q; i++ ){

	cin>>a>>b>>c;
	cout<<(a+b+c)/2<<endl;
}

}


#include<bits/stdc++.h>
using namespace std;
int main()

{

long long q,a,b,c;
cin>>q;

for ( int i=0; i<q; i++){

cin>>a>>b>>c;

cout<<(a+b+c)/2<<endl;
}

}


#include <iostream>

using namespace std;

int main()
{
 long long i,n,a,c,b,v;
for(i=0;n>=i;i++)
{

    cin>>a>>b>>c;
    v=(a+b+c)/2;
    cout<<v<<endl;
}
}


#include <iostream>

using namespace std;

int main()
{
 long long i,n,a,c,b,v;
 cin>>n;
for(i=0;n>=i;i++)
{

    cin>>a>>b>>c;
    v=(a+b+c);
    if(v%2==1)
        v--;
    cout<<v/2<<endl;
}
}


#include <iostream>

using namespace std;
 long long i,n,a,c,b,v;
int main()
{
 cin>>n;
for(i=0;n>i;i++)
{

    cin>>a>>b>>c;
    v=(a+b+c);
    cout<<v/2<<endl;
}
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="11" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/11" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/11" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include <iostream>

using namespace std;
 long long i,n,a,c,b,v;
int main()
{

 cin>>n;
for(i=0;n>=i;i++)
{

    cin>>a>>b>>c;
    v=(a+b+c);
    if(v%2==1)
        v--;
    cout<<v/2<<endl;
}
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="1" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/1" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/1" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include <iostream>

using namespace std;

int main ()
{
       unsigned long k, a, b, c;
       cin >> k;
       unsigned long l[k + 9];
       for (unsigned long i = 0; i < k; i++)
       {
              cin >> a >> b >> c;
              l[i] = (a + b + c) / 2;
       }

       for (unsigned long i = 0; i < k; i++)
              cout << l[i] << '\n';

       return 0;
}


#include <iostream>

using namespace std;

int main ()
{
       unsigned long k, a, b, c;
       cin >> k;
       unsigned long l[k + 9];
       for (int i = 0; i < k; i++)
       {
              cin >> a >> b >> c;
              l[i] = (a + b + c) / 2;
       }

       for (int i = 0; i < k; i++)
              cout << l[i] << '\n';

       return 0;
}


#include <iostream>

using namespace std;

int main ()
{
       int k, a, b, c;
       cin >> k;
       int l[k + 9];
       while (k--)
       {
              cin >> a >> b >> c;
              l[k] = (a + b + c) / 2;
       }

       for (int i = 0; i < k; i++)
              cout << l[i] << '\n';

       return 0;
}


#include <iostream>

using namespace std;

int main ()
{
       int k, a, b, c;
       cin >> k;
       int l[k + 9];
       for (int i = 0; i < k; i++)
       {
              cin >> a >> b >> c;
              l[i] = (a + b + c) / 2;
       }

       for (int i = 0; i < k; i++)
              cout << l[i] << '\n';

       return 0;
}


#include <iostream>

using namespace std;

int main ()
{
       int k, a, b, c;
       cin >> k;
       int a[k + 9];
       while (k--)
       {
              cin >> a >> b >> c;
              a[k] = (a + b + c) / 2;
       }

       for (int i = 0; i < k; i++)
              cout << a[i] << '\n';

       return 0;
}


#include <iostream>

using namespace std;

int main ()
{
       long long k, a, b, c;
       cin >> k;
       long long l[k + 9];
       for (long long i = 0; i < k; i++)
       {
              cin >> a >> b >> c;
              l[i] = (a + b + c) / 2;
       }

       for (long long i = 0; i < k; i++)
              cout << l[i] << '\n';

       return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
       int t;
                       scanf("%d",&t);
                       while(t--)
                       {
                                              long long a,b,c;
                                              scanf("%ld%ld%ld",&a,&b,&c);
                                              printf("%ld\n",(a+b+c+1)/2);
                       }

    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
       int t;
                       scanf("%d",&t);
                       while(t--)
                       {
                                              long long a,b,c,t;
                                              scanf("%ld%ld%ld",&a,&b,&c);
                           if(a>b)
                           {
                              t=a;
                               a=b;
                               b=t;
                           }
                           if(b>c)
                           {
                               t=b;
                               b=c;
                               c=t;
                           }
                           if(a>b)
                           {
                              t=a;
                               a=b;
                               b=t;
                           }

                            if((c-(b-a))%2==0)
                           printf("%ld\n",(a+b+c)/2);
                           else printf("%ld\n",(a+b+c-1)/2);
                       }

    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
       int ta;
                       scanf("%d",&ta);
                       while(ta--)
                       {
                                              long long a,b,c,t;
                                              scanf("%lld%lld%lld",&a,&b,&c);
                           if(a>b)
                           {
                              t=a;
                               a=b;
                               b=t;
                           }
                           if(b>c)
                           {
                               t=b;
                               b=c;
                               c=t;
                           }
                           if(a>b)
                           {
                              t=a;
                               a=b;
                               b=t;
                           }

                            //if((c-(b-a))%2==0)
                           printf("%lld\n",b+(c-b+a)/2);
                           //else printf("%ld\n",(a+b+c-1)/2);
                       }

    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
       int ta;
                       scanf("%d",&ta);
                       while(ta--)
                       {
                                              long long a,b,c,t;
                                              scanf("%ld%ld%ld",&a,&b,&c);
                           if(a>b)
                           {
                              t=a;
                               a=b;
                               b=t;
                           }
                           if(b>c)
                           {
                               t=b;
                               b=c;
                               c=t;
                           }
                           if(a>b)
                           {
                              t=a;
                               a=b;
                               b=t;
                           }

                            //if((c-(b-a))%2==0)
                           printf("%ld\n",b+(c-b+a)/2);
                           //else printf("%ld\n",(a+b+c-1)/2);
                       }

    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
       int t;
                       scanf("%d",&t);
                       while(t--)
                       {
                                              long long a,b,c,t;
                                              scanf("%ld%ld%ld",&a,&b,&c);
                           if(a>b)
                           {
                              t=a;
                               a=b;
                               b=t;
                           }
                           if(b>c)
                           {
                               t=b;
                               b=c;
                               c=t;
                           }
                           if(a>b)
                           {
                              t=a;
                               a=b;
                               b=t;
                           }

                            //if((c-(b-a))%2==0)
                           printf("%ld\n",b+(c-b+a)/2);
                           //else printf("%ld\n",(a+b+c-1)/2);
                       }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,a,b,c;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,a,b,c;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,a,b,c;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,a,b,c;
    cin>>t;
    for(int i=0;i<=t;i++)
    {
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int q,a,b,c;
	cin>>q;
	while(q != 0){
		cin>>a;
		cin>>b;
		cin>>c;
		int sum = a+b+c;
		if(sum%2 == 0){
			cout<< sum/2<<endl;
		}
		else{
			cout<< (sum -1)/2<<endl;
		}
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		long long a, b, c;
		cin >> a >> b >> c;
		cout << (a + b + c) / 2 << endl;
	}

	return 0;

}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int q,x,y,z;
	cin>>q;
	int m = q;
	vector<int> a,b,c;
	while(q != 0){
		cin>>x;
		a.push_back(x);
		cin>>y;
		b.push_back(y);
		cin>>z;
		c.push_back(z);
		q--;
	}

	for(int i = 0; i<m; i++){
		int sum = a[i]+b[i]+c[i];
		if(sum%2 == 0){
			cout<< sum/2<<endl;
		}
		else{
			cout<< (sum -1)/2<<endl;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int q,x,y,z;
	cin>>q;
	int m = q;
	vector<long long> a,b,c;
	while(q != 0){
		cin>>x;
		a.push_back(x);
		cin>>y;
		b.push_back(y);
		cin>>z;
		c.push_back(z);
		q--;
	}

	for(int i = 0; i<m; i++){
		long long sum = a[i]+b[i]+c[i];
		long long ans = sum/2;
			cout<< ans<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int q,x,y,z;
	cin>>q;
	int m = q;
	vector<int> a,b,c;
	while(q != 0){
		cin>>x;
		a.push_back(x);
		cin>>y;
		b.push_back(y);
		cin>>z;
		c.push_back(z);
		q--;
	}

	for(int i = 0; i<m; i++){
		int sum = a[i]+b[i]+c[i];
		int ans = sum/2;
			cout<< ans<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int q,x,y,z;
	cin>>q;
	int m = q;
	vector<long long> a,b,c;
	while(q != 0){
		cin>>x;
		a.push_back(x);
		cin>>y;
		b.push_back(y);
		cin>>z;
		c.push_back(z);
		q--;
	}

	for(int i = 0; i<m; i++){
		long long sum = a[i]+b[i]+c[i];
		 long long ans = sum/2;
			cout<< ans<<endl;
	}

}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int q,i,j,x,a,b,u;
	 long long int s[3];
	cin>>q;
	for(i=0;i<q;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>s[j];
		}

		cout<<(a+b+c)/2<<endl;
}

	}


#include<iostream>
#include<vector>
#include<algorithm>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int main()
{
	int q,i,j,x;
	 cpp_int s[3],a,b,u;
	cin>>q;
	for(i=0;i<q;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>s[j];
		}
		sort(s,s+3);
		a=s[0];b=s[1];
		if(a==b)
		{
		a=a+s[2]/2;
		b=b+s[2]/2;}
		else
		{
		u=b-a;
		a=a+u;
		a=a+(s[2]-u)/2;
		b=b+(s[2]-u)/2;
		}

		cout<<a<<endl;
}

	}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int q,i,j,x;
	 long long int  s[3],a,b,u;
	cin>>q;
	for(i=0;i<q;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>s[j];
		}
		sort(s,s+3);
		a=s[0];b=s[1];
		if(a==b)
		{
		a=a+s[2]/2;
		b=b+s[2]/2;}
		else
		{
		u=b-a;
		a=a+u;
		a=a+(s[2]-u)/2;
		b=b+(s[2]-u)/2;
		}

		cout<<a<<endl;
}

	}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int q,i,j,x,a,b,u;
	 long long int s[3];
	cin>>q;
	for(i=0;i<q;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>s[j];
		}
		sort(s,s+3);
		a=s[0];b=s[1];
		if(a==b)
		{
		a=a+s[2]/2;
		b=b+s[2]/2;}
		else
		{
		u=b-a;
		a=a+u;
		a=a+(s[2]-u)/2;
		b=b+(s[2]-u)/2;
		}

		cout<<(s[0]+s[1]+s[2])/2<<endl;
}

	}


#include<iostream>
#include<vector>
#include<algorithm>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int main()
{
	int q,i,j,x,a,b,u;
	 cpp_int s[3];
	cin>>q;
	for(i=0;i<q;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>s[j];
		}

		cout<<(a+b+c)/2<<endl;
}

	}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int q;
    cin>>q;
    long long int z[3];
    long long int maxx,med,low;
    long long int a,b,c;
    while(q--)
    {
        cin>>a>>b>>c;
        z[0]=a;
        z[1]=b;
        z[2]=c;
    sort(z,z+3);

    if(z[2]==z[1]+z[0])
    {
        cout<<z[2]<<endl;
    }
        else
        {
            long long int x =(z[2]-z[1]+z[0]);
            if(x%2==0)
                x=x/2;
            else
                x=x/2+1;
            cout<<x<<endl;
            cout<<z[1]+x<<endl;
        }
    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int q;
    cin>>q;
    long long int z[3];
    long long int maxx,med,low;
    long long int a,b,c;
    while(q--)
    {
        cin>>a>>b>>c;
        z[0]=a;
        z[1]=b;
        z[2]=c;
    sort(z,z+3);
    for(int i=0;i<3;i++)
        cout<<z[i]<<" ";
    if(z[2]==z[1]+z[0])
    {
        cout<<z[2]<<endl;
    }
    else if(a==b==c)
            cout<<a/2<<endl;
        else
        {
            long long int x =(z[2]-z[1]+z[0])/2;
    cout<<x<<endl;
            cout<<z[1]+x<<endl;
        }
    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int q;
    cin>>q;
    long long int z[3];
    long long int maxx,med,low;
    long long int a,b,c;
    while(q--)
    {
        cin>>a>>b>>c;
        z[0]=a;
        z[1]=b;
        z[2]=c;
    sort(z,z+3);

    if(z[2]==z[1]+z[0])
    {
        cout<<z[2]<<endl;
    }
    else if(a==b==c)
            cout<<a+a/2<<endl;
        else
        {
            long long int x =(z[2]-z[1]+z[0])/2;
            cout<<z[1]+x<<endl;
        }
    }
}


#include<iostream>
using namepsace std;
int main()
{

    int q;
    cin>>q;
    long long int a,b,c;

    while(q--)
    {
         cin>>a>>b>>c;
         cout<<(a+b+c)/2<<endl;
    }

}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int q;
    cin>>q;
    long long int z[3];
    long long int maxx,med,low;
    long long int a,b,c;
    while(q--)
    {
        cin>>a>>b>>c;
        z[0]=a;
        z[1]=b;
        z[2]=c;
    sort(z,z+3);

    if(z[2]==z[1]+z[0])
    {
        cout<<z[2]<<endl;
    }
    else if(a==b==c)
            cout<<a/2<<endl;
        else
        {
            long long int x =(z[2]-z[1]+z[0])/2;
            cout<<z[1]+x<<endl;
        }
    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int q;
    cin>>q;
    long long int a,b,c;
    while(q--)
    {
        cin>>a>>b>>c;
	cout<<(a+b+c)/2<<endl;

        }
    }


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int q;
    cin>>q;
    long long int z[3];
    long long int maxx,med,low;
    long long int a,b,c;
    while(q--)
    {
        cin>>a>>b>>c;
        z[0]=a;
        z[1]=b;
        z[2]=c;
    sort(z,z+3);

    if(z[2]==z[1]+z[0])
    {
        cout<<z[2]<<endl;
    }
        else
        {
            long long int x =ceil(float(z[2]-z[1]+z[0])/2);
            cout<<z[1]+x<<endl;
        }
    }
}


#include<iostream>
using namespace std;
int main()
{
    int q;
    cin>>q;
    long long int a,b,c;
    while(q--)
    {
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }

}


#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
const int N=5005;
const int INF=1e9;
using namespace std;

int Q;
LL a,b,c;

void SOLVE(){
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a>b)swap(a,b);
	c-=(b-a);
	if(c<0)printf("%lld\n",a);
	else printf("%lld\n",b+c/2);
}

int main(){
	scanf("%d",&Q);
	while(Q--)SOLVE();
	return 0;
}


#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
const int N=5005;
const int INF=1e9;
using namespace std;

int Q;
LL a,b,c;

void SOLVE(){
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a>b)swap(a,b);
	if(c<(b-a))printf("%lld\n",a+c);
	else {
		c-=(b-a);
		printf("%lld\n",b+c/2);
	}
}

int main(){
	scanf("%d",&Q);
	while(Q--)SOLVE();
	return 0;
}


#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
using namespace std;

int Q;
LL a,b,c;

void SOLVE(){
	scanf("%lld%lld%lld",&a,&b,&c);
	if(c<abs(b-a))printf("%lld\n",min(a,b)+c);
	else {
		c-=abs(b-a);
		printf("%lld\n",max(a,b)+c/2);
	}
}

int main(){
	scanf("%d",&Q);
	while(Q--)SOLVE();
	return 0;
}


#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
using namespace std;

int Q;
LL a[4];

void SOLVE(){
	rep(i,0,2)scanf("%lld",&a[i]);
	sort(a,a+2+1);
	a[2]-=a[1]-a[0];
	printf("%lld\n",a[1]+a[2]/2);
}

int main(){
	scanf("%d",&Q);
	while(Q--)SOLVE();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long a,b,c,p,q,r,u,v,w,ans;
        cin>>a>>b>>c;
        p=abs(a-b);
        q=abs(b-c);
        r=abs(a-c);
        if(c>=p) u=max(a,b)+((c-p)/2);
        else u=min(a,b)+c;
        if(a>=q) v=max(c,b)+((a-q)/2);
        else v=min(c,b)+a;
        if(b>=r) w=max(a,c)+((b-r)/2);
        else w=min(a,c)+b;
        ans=max(max(u,v),w);
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long inf = 9223372036854775807ll;
const int iinf = 2147483647;
const int limit = 524288;
using namespace std;
bool sync_with_stdio (bool sync = false);

struct vec3
{
    ld coord[4];
    vec3()
    {
        coord[1] = 0; coord[2] =0; coord[3] = 1;
    }

    ld len(){ return sqrt(coord[1] * coord[1] + coord[2] * coord[2]);}

    ld& operator [](int i){ return coord[i];}
};

//local operators for RP2, A(v - w) != Av - Aw with this
vec3 operator -(vec3 v, vec3 w)
{
    vec3 res;
    rep(i, 1, 3)
        res[i] = v[i] - w[i];
    return res;
}

vec3 operator *(ld a, vec3 v)
{
    vec3 res;
    rep(i, 1, 3)
        res[i] = a * v[i];
    return res;
}

struct mat3
{
    ld tab[4][4];
    mat3()
    {
        rep(i, 1, 4)
            rep(j, 1, 4)
                tab[i][j] = 0;
        rep(i, 1, 4)
            tab[i][i] = 1;
    }
    ld* operator [](int i){ return tab[i];}
};

mat3 operator *(mat3 a, mat3 b)
{
    mat3 res;
    rep(i, 1, 4)
            res[i][i] = 0;
    rep(i, 1, 4)
        rep(j, 1, 4)
            rep(k, 1, 4)
                res[i][j] += a[i][k] * b[k][j];
    return res;
}

vec3 operator *(mat3 a, vec3 v)
{
    vec3 res; res[3] = 0;
    rep(i, 1, 4)
        rep(j, 1, 4)
            res[i] += a[i][j] * v[j];
    return res;
}

struct seg_t
{
    vector<mat3> tab;

    seg_t()
    :tab{vector<mat3>(2 * limit, mat3())}{}

    void ins(int ind, mat3 a)
    {
        ind += limit;
        tab[ind] = a * tab[ind]; ind /= 2;
        while(ind)
        {
            tab[ind] = tab[2 * ind] * tab[2 * ind + 1];
            ind /= 2;
        }
    }

    mat3 sum(int beg, int fin)
    {
        beg += limit, fin += limit;
        if(beg == fin)
            return tab[beg];
        mat3 res_l = tab[beg], res_r = tab[fin];
        while(fin - beg > 1)
        {
            if(beg % 2 == 0)
                res_l = res_l * tab[beg + 1];
            if(fin % 2 == 1)
                res_r = tab[fin - 1] * res_r;
            fin /= 2; beg /= 2;
        }
        return res_l * res_r;
    }
};

#define PI 3.14159265

mat3 rot(int ang)
{
    ld angl = ld(ang) * PI / 180.0;
    mat3 res;
    res[1][1] = cos(angl);
    res[2][2] = cos(angl);
    res[1][2] = -sin(angl);
    res[2][1] = sin(angl);
    return res;
}

mat3 trans(vec3 v)
{
    mat3 res;
    res[1][3] = v[1];
    res[2][3] = v[2];
    return res;
}

int main(){
    int n, m; cin >> n >> m;
    seg_t Tree;

    vec3 e_1; e_1[1] = 1.0;
    rep(i, 1, n + 1)
        Tree.ins(i, trans(e_1));
    rep(i, 0, m)
    {
        int x, y, z; cin >> x >> y >> z;
        if(x == 1)
        {
            vec3 temp;
            temp = Tree.sum(y, y) * temp;
            Tree.ins(y, trans((ld(z) / temp.len()) * temp));
        }
        if(x == 2)
        {
            vec3 temp1;
            temp1 = Tree.sum(0, y - 1) * temp1;
            Tree.ins(y, rot(-z));
        }
        vec3 ans;
        ans = Tree.sum(0, n + 1) * ans;
        cout << fixed << setprecision(15) << ans[1] << " " << ans[2] << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long inf = 9223372036854775807ll;
const int iinf = 2147483647;
const int limit = 524288;
using namespace std;
bool sync_with_stdio (bool sync = false);

struct vec3
{
    ld coord[3];
    vec3()
    {
        coord[0] = 0; coord[1] =0; coord[2] = 1;
    }

    ld len(){ return sqrt(coord[0] * coord[0] + coord[1] * coord[1]);}

    ld& operator [](int i){ return coord[i];}
};

//local operators for RP2, A(v - w) != Av - Aw with this
vec3 operator -(vec3 v, vec3 w)
{
    vec3 res;
    rep(i, 0, 2)
        res[i] = v[i] - w[i];
    return res;
}

vec3 operator *(ld a, vec3 v)
{
    vec3 res;
    rep(i, 0, 2)
        res[i] = a * v[i];
    return res;
}

struct mat3
{
    ld tab[3][3];
    mat3()
    {
        rep(i, 0, 3)
            rep(j, 0, 3)
                tab[i][j] = 0;
        rep(i, 0, 3)
            tab[i][i] = 1;
    }
    ld* operator [](int i){ return tab[i];}
};

mat3 operator *(mat3 a, mat3 b)
{
    mat3 res;
    rep(i, 0, 3)
            res[i][i] = 0;
    rep(i, 0, 3)
        rep(j, 0, 3)
            rep(k, 0, 3)
                res[i][j] += a[i][k] * b[k][j];
    return res;
}

vec3 operator *(mat3 a, vec3 v)
{
    vec3 res; res[2] = 0;
    rep(i, 0, 3)
        rep(j, 0, 3)
            res[i] += a[i][j] * v[j];
    return res;
}

struct seg_t
{
    vector<mat3> tab;

    seg_t()
    :tab{vector<mat3>(2 * limit, mat3())}{}

    void ins(int ind, mat3 a)
    {
        ind += limit;
        tab[ind] = a * tab[ind]; ind /= 2;
        while(ind)
        {
            tab[ind] = tab[2 * ind] * tab[2 * ind + 1];
            ind /= 2;
        }
    }

    mat3 sum(int beg, int fin)
    {
        beg += limit, fin += limit;
        if(beg == fin)
            return tab[beg];
        mat3 res_l = tab[beg], res_r = tab[fin];
        while(fin - beg > 1)
        {
            if(beg % 2 == 0)
                res_l = res_l * tab[beg + 1];
            if(fin % 2 == 1)
                res_r = tab[fin - 1] * res_r;
            fin /= 2; beg /= 2;
        }
        return res_l * res_r;
    }
};

#define PI 3.14159265

mat3 rot(int ang)
{
    ld angl = ld(ang) * PI / 180.0;
    mat3 res;
    res[0][0] = cos(angl);
    res[1][1] = cos(angl);
    res[0][1] = -sin(angl);
    res[1][0] = sin(angl);
    return res;
}

mat3 trans(vec3 v)
{
    mat3 res;
    res[0][2] = v[0];
    res[1][2] = v[1];
    return res;
}

int main(){
    int n, m; cin >> n >> m;
//     n = 300000; m = 300000;
    seg_t Tree;

    vec3 e_1; e_1[0] = 1.0;
    rep(i, 1, n + 1)
        Tree.tab[limit + i] = trans(e_1);//.ins(i, trans(e_1));
    for(int i = limit - 1; i > 0; i--)
        Tree.tab[i] = Tree.tab[2 * i] * Tree.tab[2 * i + 1];
    vector<mat3> rots(360);
    rep(i, 0, 360)
        rots[i] = rot(-i);
    rep(i, 0, m)
    {
        int x, y, z; cin >> x >> y >> z;
//         x = 1; y = 1; z = 1;
        if(x == 1)
        {
            vec3 temp;
            temp = Tree.sum(y, y) * temp;
            Tree.ins(y, trans((ld(z) / temp.len()) * temp));
        }
        if(x == 2)
            Tree.ins(y, rots[z]);
        vec3 ans;
        ans = Tree.tab[1] * ans;
//         ans = Tree.sum(0, n + 1) * ans;
        cout << fixed << setprecision(15) << ans[0] << " " << ans[1] << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long inf = 9223372036854775807ll;
const int iinf = 2147483647;
const int limit = 524288;
using namespace std;
bool sync_with_stdio (bool sync = false);

struct vec3
{
    ld coord[3];
    vec3()
    {
        coord[0] = 0; coord[1] =0; coord[2] = 1;
    }

    ld len(){ return sqrt(coord[0] * coord[0] + coord[1] * coord[1]);}

    ld& operator [](int i){ return coord[i];}
};

//local operators for RP2, A(v - w) != Av - Aw with this
vec3 operator -(vec3 v, vec3 w)
{
    vec3 res;
    rep(i, 0, 2)
        res[i] = v[i] - w[i];
    return res;
}

vec3 operator *(ld a, vec3 v)
{
    vec3 res;
    rep(i, 0, 2)
        res[i] = a * v[i];
    return res;
}

struct mat3
{
    ld tab[3][3];
    mat3()
    {
        rep(i, 0, 3)
            rep(j, 0, 3)
                tab[i][j] = 0;
        rep(i, 0, 3)
            tab[i][i] = 1;
    }
    ld* operator [](int i){ return tab[i];}
};

mat3 operator *(mat3 a, mat3 b)
{
    mat3 res;
    rep(i, 0, 3)
            res[i][i] = 0;
    rep(i, 0, 3)
        rep(j, 0, 3)
            rep(k, 0, 3)
                res[i][j] += a[i][k] * b[k][j];
    return res;
}

vec3 operator *(mat3 a, vec3 v)
{
    vec3 res; res[2] = 0;
    rep(i, 0, 3)
        rep(j, 0, 3)
            res[i] += a[i][j] * v[j];
    return res;
}

struct seg_t
{
    vector<mat3> tab;

    seg_t()
    :tab{vector<mat3>(2 * limit, mat3())}{}

    void ins(int ind, mat3 a)
    {
        ind += limit;
        tab[ind] = a * tab[ind]; ind /= 2;
        while(ind)
        {
            tab[ind] = tab[2 * ind] * tab[2 * ind + 1];
            ind /= 2;
        }
    }

    mat3 sum(int beg, int fin)
    {
        beg += limit, fin += limit;
        if(beg == fin)
            return tab[beg];
        mat3 res_l = tab[beg], res_r = tab[fin];
        while(fin - beg > 1)
        {
            if(beg % 2 == 0)
                res_l = res_l * tab[beg + 1];
            if(fin % 2 == 1)
                res_r = tab[fin - 1] * res_r;
            fin /= 2; beg /= 2;
        }
        return res_l * res_r;
    }
};

#define PI 3.14159265

mat3 rot(int ang)
{
    ld angl = ld(ang) * PI / 180.0;
    mat3 res;
    res[0][0] = cos(angl);
    res[1][1] = cos(angl);
    res[0][1] = -sin(angl);
    res[1][0] = sin(angl);
    return res;
}

mat3 trans(vec3 v)
{
    mat3 res;
    res[0][2] = v[0];
    res[1][2] = v[1];
    return res;
}

int main(){
    int n, m; cin >> n >> m;
//     n = 300000; m = 300000;
    seg_t Tree;

    vec3 e_1; e_1[0] = 1.0;
    rep(i, 1, n + 1)
        Tree.ins(i, trans(e_1));
    vector<mat3> rots(360);
    rep(i, 0, 360)
        rots[i] = rot(-i);
    rep(i, 0, m)
    {
        int x, y, z; cin >> x >> y >> z;
//         x = 1; y = 1; z = 1;
        if(x == 1)
        {
            vec3 temp;
            temp = Tree.sum(y, y) * temp;
            Tree.ins(y, trans((ld(z) / temp.len()) * temp));
        }
        if(x == 2)
            Tree.ins(y, rots[z]);
        vec3 ans;
        ans = Tree.sum(0, n + 1) * ans;
        cout << fixed << setprecision(15) << ans[0] << " " << ans[1] << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
double precalSin[360];
double precalCos[360];
void fixAngle(int &x){
    while(x < 0)    x += 360;
    while(x >= 360)    x -= 360;
}
struct point{
    double x, y;
    int angle, id;
    point (double x=0, double y=0, int angle=0, int id=0): x(x), y(y), angle(angle), id(id) {}
    void rotate(point root, int angleR){
        fixAngle(angleR);
        double tmpX = (x - root.x) * precalCos[angleR] - (y - root.y) * precalSin[angleR];
        double tmpY = (x - root.x) * precalSin[angleR] + (y - root.y) * precalCos[angleR];
        x = tmpX + root.x;
        y = tmpY + root.y;
        angle += angleR;
        fixAngle(angle);
    }
};
double distance(point a,point b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
struct query{
    int type, id;
    double x, y, len;
    int angle;
    query(int type=0,int id=0,double x=0, double y=0, double len=0, int angle = 0): type(type), id(id), x(x), y(y), len(len), angle(angle) {}
    void construct(int ttype, int iid, point xx, double vval){
        if (ttype == 1){
            type = 1;
            id = iid;
            x = xx.x;
            y = xx.y;
            len = vval;
            angle = xx.angle;
        }
        else{
            type = 2;
            id = iid;
            x = xx.x;
            y = xx.y;
            angle = (int) vval;
        }
    }
};
point a[300005];
int n, q;
vector <query> buffer;
double tmpLen[300005];
int tmpAngle[300005];
void rebuild(){
    for(int i=1;i<=n;i++)
        tmpLen[i] = distance(a[i], a[i-1]),
        tmpAngle[i] = a[i].angle - a[i-1].angle,
        fixAngle(tmpAngle[i]);

    for(auto v: buffer){
        if (v.type == 1){
            tmpLen[v.id] += v.len;
        }
        else
            tmpAngle[v.id] += v.angle,
            fixAngle(tmpAngle[v.id]);
    }
    for(int i=1;i<=n;i++){
        a[i].x = a[i-1].x + precalCos[a[i-1].angle] * tmpLen[i];
        a[i].y = a[i-1].y + precalSin[a[i-1].angle] * tmpLen[i];
        a[i].angle = a[i-1].angle;
        a[i].rotate(a[i-1], tmpAngle[i]);
    }
    buffer.clear();
}
point getInformation(point cur){
    for (auto v: buffer){
        if (v.id > cur.id)    continue;
        if (v.type == 1){
             cur.x += precalCos[v.angle] * v.len;
             cur.y += precalSin[v.angle] * v.len;
        }
        else{
            point tmp;
            tmp.x = v.x;
            tmp.y = v.y;
            cur.rotate(tmp, v.angle);
        }
    }
    return cur;
}
int main(){
    iostream::sync_with_stdio(0);
    cin >> n >> q;
    for(int i=0;i<360;i++){
        precalSin[i] = sin(pi * i / 180);
        precalCos[i] = cos(pi * i / 180);
    }

    for(int i=1;i<=n;i++)
        a[i].x = i,
        a[i].id = i;

    while(q--){
        int type, id;
        cin >> type >> id;
        if (type == 1){
            int len;
            cin >> len;
            point cur = getInformation(a[id]);
            query tmp;
            tmp.construct(1, id, cur, len);
            buffer.push_back(tmp);
        }
        else{
            int angle;
            cin >> angle;
            angle = - angle;
            fixAngle(angle);

            point befCur = getInformation(a[id-1]);
            query tmp;
            tmp.construct(2, id, befCur, angle);
            buffer.push_back(tmp);
        }
        point fin = getInformation(a[n]);
        cout << fixed << setprecision(10) << fin.x << ' ' << fin.y << '\n';
        if (buffer.size() == 500)
            rebuild();
    }
}


#include <bits/stdc++.h>
using namespace std;
const float pi = acos(-1);
float precalSin[360];
float precalCos[360];
void fixAngle(int &x){
    while(x < 0)    x += 360;
    while(x >= 360)    x -= 360;
}
struct point{
    float x, y;
    int angle, id;
    point (float x=0, float y=0, int angle=0, int id=0): x(x), y(y), angle(angle), id(id) {}
    void rotate(point root, int angleR){
        fixAngle(angleR);
        float tmpX = (x - root.x) * precalCos[angleR] - (y - root.y) * precalSin[angleR];
        float tmpY = (x - root.x) * precalSin[angleR] + (y - root.y) * precalCos[angleR];
        x = tmpX + root.x;
        y = tmpY + root.y;
        angle += angleR;
        fixAngle(angle);
    }
};
float distance(point a,point b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
struct query{
    int type, id;
    float x, y, len;
    int angle;
    query(int type=0,int id=0,float x=0, float y=0, float len=0, int angle = 0): type(type), id(id), x(x), y(y), len(len), angle(angle) {}
    void construct(int ttype, int iid, point xx, float vval){
        if (ttype == 1){
            type = 1;
            id = iid;
            x = xx.x;
            y = xx.y;
            len = vval;
            angle = xx.angle;
        }
        else{
            type = 2;
            id = iid;
            x = xx.x;
            y = xx.y;
            angle = (int) vval;
        }
    }
};
point a[300005];
int n, q;
vector <query> buffer;
float tmpLen[300005];
int tmpAngle[300005];
void rebuild(){
    for(int i=1;i<=n;i++)
        tmpLen[i] = distance(a[i], a[i-1]),
        tmpAngle[i] = a[i].angle - a[i-1].angle,
        fixAngle(tmpAngle[i]);

    for(auto v: buffer){
        if (v.type == 1){
            tmpLen[v.id] += v.len;
        }
        else
            tmpAngle[v.id] += v.angle,
            fixAngle(tmpAngle[v.id]);
    }
    for(int i=1;i<=n;i++){
        a[i].x = a[i-1].x + precalCos[a[i-1].angle] * tmpLen[i];
        a[i].y = a[i-1].y + precalSin[a[i-1].angle] * tmpLen[i];
        a[i].angle = a[i-1].angle;
        a[i].rotate(a[i-1], tmpAngle[i]);
    }
    buffer.clear();
}
point getInformation(point cur){
    for (auto v: buffer){
        if (v.id > cur.id)    continue;
        if (v.type == 1){
             cur.x += precalCos[v.angle] * v.len;
             cur.y += precalSin[v.angle] * v.len;
        }
        else{
            point tmp;
            tmp.x = v.x;
            tmp.y = v.y;
            cur.rotate(tmp, v.angle);
        }
    }
    return cur;
}
int main(){
    iostream::sync_with_stdio(0);
    cin >> n >> q;
    for(int i=0;i<360;i++){
        precalSin[i] = sin(pi * i / 180);
        precalCos[i] = cos(pi * i / 180);
    }

    for(int i=1;i<=n;i++)
        a[i].x = i,
        a[i].id = i;

    while(q--){
        int type, id;
        cin >> type >> id;
        if (type == 1){
            int len;
            cin >> len;
            point cur = getInformation(a[id]);
            query tmp;
            tmp.construct(1, id, cur, len);
            buffer.push_back(tmp);
        }
        else{
            int angle;
            cin >> angle;
            angle = - angle;
            fixAngle(angle);

            point befCur = getInformation(a[id-1]);
            query tmp;
            tmp.construct(2, id, befCur, angle);
            buffer.push_back(tmp);
        }
        point fin = getInformation(a[n]);
        cout << fixed << setprecision(10) << fin.x << ' ' << fin.y << '\n';
        if (buffer.size() == 500)
            rebuild();
    }
}


#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
struct point{
    double x, y, angle, id;
    point (double x=0, double y=0, double angle=0, double id=0): x(x), y(y), angle(angle), id(id) {}
    void rotate(point root, double angleR){
        double tmpX = (x - root.x) * cos(angleR) - (y - root.y) * sin(angleR);
        double tmpY = (x - root.x) * sin(angleR) + (y - root.y) * cos(angleR);
        x = tmpX + root.x;
        y = tmpY + root.y;
        angle += angleR;
    }
};
double distance(point a,point b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
struct query{
    int type, id;
    double x, y, len, angle;
    query(int type=0,int id=0,double x=0, double y=0, double len=0, double angle = 0): type(type), id(id), x(x), y(y), len(len), angle(angle) {}
    void construct(int ttype, int iid, point xx, double vval){
        if (ttype == 1){
            type = 1;
            id = iid;
            x = xx.x;
            y = xx.y;
            len = vval;
            angle = xx.angle;
        }
        else{
            type = 2;
            id = iid;
            x = xx.x;
            y = xx.y;
            angle = vval;
        }
    }
};
point a[300005];
int n, q;
vector <query> buffer;
double tmpLen[300005], tmpAngle[300005];
void rebuild(){
    for(int i=1;i<=n;i++)
        tmpLen[i] = distance(a[i], a[i-1]),
        tmpAngle[i] = a[i].angle - a[i-1].angle;
    for(auto v: buffer){
        if (v.type == 1){
            tmpLen[v.id] += v.len;
        }
        else
            tmpAngle[v.id] += v.angle;
    }
    for(int i=1;i<=n;i++){
        a[i].x = a[i-1].x + cos(a[i-1].angle) * tmpLen[i];
        a[i].y = a[i-1].y + sin(a[i-1].angle) * tmpLen[i];
        a[i].angle = a[i-1].angle;
        a[i].rotate(a[i-1], tmpAngle[i]);
    }
    buffer.clear();
}
point getInformation(point cur){
    for (auto v: buffer){
        if (v.id > cur.id)    continue;
        if (v.type == 1){
             cur.x += cos(v.angle) * v.len;
             cur.y += sin(v.angle) * v.len;
        }
        else{
            point tmp;
            tmp.x = v.x;
            tmp.y = v.y;
            cur.rotate(tmp, v.angle);
        }
    }
    return cur;
}
int main(){
    iostream::sync_with_stdio(0);
    cin >> n >> q;
    for(int i=1;i<=n;i++)
        a[i].x = i,
        a[i].id = i;

    while(q--){
        int type, id;
        cin >> type >> id;
        if (type == 1){
            int len;
            cin >> len;
            point cur = getInformation(a[id]);
            query tmp;
            tmp.construct(1, id, cur, len);
            buffer.push_back(tmp);
        }
        else{
            double angle;
            cin >> angle;
            angle = angle / 180 * pi;
            angle = - angle;
            point befCur = getInformation(a[id-1]);
            query tmp;
            tmp.construct(2, id, befCur, angle);
            buffer.push_back(tmp);
        }
        point fin = getInformation(a[n]);
        cout << fixed << setprecision(10) << fin.x << ' ' << fin.y << '\n';
        if (buffer.size() == 500)
            rebuild();
//        for(int i=1;i<=n;i++){
//            cout << a[i].x << ' ' << a[i].y << endl;
//        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
double precalSin[360];
double precalCos[360];
void fixAngle(int &x){
    while(x < 0)    x += 360;
    while(x >= 360)    x -= 360;
}
struct point{
    double x, y;
    int angle, id;
    point (double x=0, double y=0, int angle=0, int id=0): x(x), y(y), angle(angle), id(id) {}
    void rotate(point root, int angleR){
        fixAngle(angleR);
        double tmpX = (x - root.x) * precalCos[angleR] - (y - root.y) * precalSin[angleR];
        double tmpY = (x - root.x) * precalSin[angleR] + (y - root.y) * precalCos[angleR];
        x = tmpX + root.x;
        y = tmpY + root.y;
        angle += angleR;
        fixAngle(angle);
    }
};
double distance(point a,point b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
struct query{
    int type, id;
    double x, y, len;
    int angle;
    query(int type=0,int id=0,double x=0, double y=0, double len=0, int angle = 0): type(type), id(id), x(x), y(y), len(len), angle(angle) {}
    void construct(int ttype, int iid, point xx, double vval){
        if (ttype == 1){
            type = 1;
            id = iid;
            x = xx.x;
            y = xx.y;
            len = vval;
            angle = xx.angle;
        }
        else{
            type = 2;
            id = iid;
            x = xx.x;
            y = xx.y;
            angle = (int) vval;
        }
    }
};
point a[300005];
int n, q;
vector <query> buffer;
double tmpLen[300005];
int tmpAngle[300005];
void rebuild(){
    for(int i=1;i<=n;i++)
        tmpLen[i] = distance(a[i], a[i-1]),
        tmpAngle[i] = a[i].angle - a[i-1].angle,
        fixAngle(tmpAngle[i]);

    for(auto v: buffer){
        if (v.type == 1){
            tmpLen[v.id] += v.len;
        }
        else
            tmpAngle[v.id] += v.angle,
            fixAngle(tmpAngle[v.id]);
    }
    for(int i=1;i<=n;i++){
        a[i].x = a[i-1].x + precalCos[a[i-1].angle] * tmpLen[i];
        a[i].y = a[i-1].y + precalSin[a[i-1].angle] * tmpLen[i];
        a[i].angle = a[i-1].angle;
        a[i].rotate(a[i-1], tmpAngle[i]);
    }
    buffer.clear();
}
point getInformation(point cur){
    for (auto v: buffer){
        if (v.id > cur.id)    continue;
        if (v.type == 1){
             cur.x += precalCos[v.angle] * v.len;
             cur.y += precalSin[v.angle] * v.len;
        }
        else{
            point tmp;
            tmp.x = v.x;
            tmp.y = v.y;
            cur.rotate(tmp, v.angle);
        }
    }
    return cur;
}
int main(){
    iostream::sync_with_stdio(0);
    cin >> n >> q;
    for(int i=0;i<360;i++){
        precalSin[i] = sin(pi * i / 180);
        precalCos[i] = cos(pi * i / 180);
    }

    for(int i=1;i<=n;i++)
        a[i].x = i,
        a[i].id = i;

    while(q--){
        int type, id;
        cin >> type >> id;
        if (type == 1){
            int len;
            cin >> len;
            point cur = getInformation(a[id]);
            query tmp;
            tmp.construct(1, id, cur, len);
            buffer.push_back(tmp);
        }
        else{
            int angle;
            cin >> angle;
            angle = - angle;
            fixAngle(angle);

            point befCur = getInformation(a[id-1]);
            query tmp;
            tmp.construct(2, id, befCur, angle);
            buffer.push_back(tmp);
        }
        point fin = getInformation(a[n]);
        cout << fixed << setprecision(10) << fin.x << ' ' << fin.y << '\n';
        if (buffer.size() == 400)
            rebuild();
    }
}


#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
double precalSin[360];
double precalCos[360];
void fixAngle(int &x){
    while(x < 0)    x += 360;
    while(x >= 360)    x -= 360;
}
struct point{
    double x, y;
    int angle, id;
    point (double x=0, double y=0, int angle=0, int id=0): x(x), y(y), angle(angle), id(id) {}
    void rotate(point root, int angleR){
        fixAngle(angleR);
        double tmpX = (x - root.x) * precalCos[angleR] - (y - root.y) * precalSin[angleR];
        double tmpY = (x - root.x) * precalSin[angleR] + (y - root.y) * precalCos[angleR];
        x = tmpX + root.x;
        y = tmpY + root.y;
        angle += angleR;
        fixAngle(angle);
    }
};
double distance(point a,point b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
struct query{
    int type, id;
    double x, y, len;
    int angle;
    query(int type=0,int id=0,double x=0, double y=0, double len=0, int angle = 0): type(type), id(id), x(x), y(y), len(len), angle(angle) {}
    void construct(int ttype, int iid, point xx, double vval){
        if (ttype == 1){
            type = 1;
            id = iid;
            x = xx.x;
            y = xx.y;
            len = vval;
            angle = xx.angle;
        }
        else{
            type = 2;
            id = iid;
            x = xx.x;
            y = xx.y;
            angle = (int) vval;
        }
    }
};
point a[300005];
int n, q;
vector <query> buffer;
double tmpLen[300005];
int tmpAngle[300005];
void rebuild(){
    for(int i=1;i<=n;i++)
        tmpLen[i] = distance(a[i], a[i-1]),
        tmpAngle[i] = a[i].angle - a[i-1].angle,
        fixAngle(tmpAngle[i]);

    for(auto v: buffer){
        if (v.type == 1){
            tmpLen[v.id] += v.len;
        }
        else
            tmpAngle[v.id] += v.angle,
            fixAngle(tmpAngle[v.id]);
    }
    for(int i=1;i<=n;i++){
        a[i].x = a[i-1].x + precalCos[a[i-1].angle] * tmpLen[i];
        a[i].y = a[i-1].y + precalSin[a[i-1].angle] * tmpLen[i];
        a[i].angle = a[i-1].angle;
        a[i].rotate(a[i-1], tmpAngle[i]);
    }
    buffer.clear();
}
point getInformation(point cur){
    for (auto v: buffer){
        if (v.id > cur.id)    continue;
        if (v.type == 1){
             cur.x += precalCos[v.angle] * v.len;
             cur.y += precalSin[v.angle] * v.len;
        }
        else{
            point tmp;
            tmp.x = v.x;
            tmp.y = v.y;
            cur.rotate(tmp, v.angle);
        }
    }
    return cur;
}
int main(){
    scanf("%d %d",&n,&q);
    for(int i=0;i<360;i++){
        precalSin[i] = sin(pi * i / 180);
        precalCos[i] = cos(pi * i / 180);
    }

    for(int i=1;i<=n;i++)
        a[i].x = i,
        a[i].id = i;

    while(q--){
        int type, id;
        scanf("%d %d",&type, &id);
        if (type == 1){
            int len;
            scanf("%d",&len);
            point cur = getInformation(a[id]);
            query tmp;
            tmp.construct(1, id, cur, len);
            buffer.push_back(tmp);
        }
        else{
            int angle;
            scanf("%d",&angle);
            angle = - angle;
            fixAngle(angle);

            point befCur = getInformation(a[id-1]);
            query tmp;
            tmp.construct(2, id, befCur, angle);
            buffer.push_back(tmp);
        }
        point fin = getInformation(a[n]);
        printf("%.10f %.10f\n", fin.x, fin.y);
        //cout << fixed << setprecision(10) << fin.x << ' ' << fin.y << '\n';
        if (buffer.size() == 550)
            rebuild();
    }
}


#include "assert.h"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

using namespace std;

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

template<typename T> inline void minimize(T &a, T b) { a = std::min(a, b); }
template<typename T> inline void maximize(T &a, T b) { a = std::max(a, b); }

template<typename T> inline void swap(pair<T, T> &p) { swap(p.first , p.second ); }

#define all(v) v.begin(),v.end()

#define endl '\n'
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define next(t, i) argument_type<void(t)>::type i; cin >> i;

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) { if (i) os << ' '; os << v[i]; } os << endl; return os; }
template <typename T1, typename T2> ostream& operator << (ostream& os, const vector<pair<T1, T2>> &v) { for (int i = 0 ; i < v.size() ; i++) { os << v[i] << endl; } return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, const pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

struct matrix {
	vector<vector<double>> mx;

	matrix() {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
	}

	matrix(int i) {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
		mx[0][2] = 1;
	}

	void print(ostream& os) {
		FOR (i, 0, 3) {
			FOR (j, 0, 3) os << mx[i][j] << ' ';
			os << endl;
		}
	}

	matrix operator *(matrix &other) {
		matrix res = matrix();
		FOR (i, 0, 3) FOR (j, 0, 3) res.mx[i][j] = 0;
		FOR (i, 0, 3) FOR (j, 0, 3) FOR (k, 0, 3) res.mx[i][j] += mx[i][k] * other.mx[k][j];

		// cerr << "1 --- " << endl;

		// print(cerr);

		// cerr << "2 ---- " << endl;
		// other.print(cerr);
		// cerr  << " result : " << endl;
		// res.print(cerr);
		// cerr << "----" << endl;

		return res;
	}
};

ostream& operator << (ostream& os, const matrix &m) {
	FOR (i, 0, 3) {
		FOR (j, 0, 3) os << m.mx[i][j] << ' ';
		os << endl;
	}
	return os;
}

template <typename T, typename TCoord>
struct Tree {
	int gp2(int n) {
		int x = 1;
		while (x < n) x += x;
		return x;
	}

	int n;
	T zero_value;
	vector<T> data;
	vector<TCoord> leftmost;
	vector<TCoord> rightmost;
	function<T(T, T)> combine;

	void init(function<T(T,T)> combine, T zero_value) {
		this->combine = combine;
		this->zero_value = zero_value;
		for (int i = n - 1 ; i ; i--) data[i] = combine(data[i + i] , data[i + i + 1]), leftmost[i] = leftmost[i + i], rightmost[i] = rightmost[i + i + 1];
	}

	void init_plain_coord() {
		leftmost = rightmost = vector<TCoord>(n + n, (TCoord) 1e20);
		for (int i = 0 ; i < n ; i++) leftmost[n + i] = rightmost[n + i] = i;
	}

	Tree() { }

	Tree(int n, function<T(T,T)> combine, T zero_value, T init_value) {
		int n1 = n;
		this->n = n = gp2(n);
		data.assign(n + n, zero_value);
		FOR (i, 0, n1) data[n + i] = init_value;

		init_plain_coord();
		init(combine, zero_value);
	}

	T getValue(TCoord l, TCoord r, int i = 1) {
		if (leftmost[i] >= l && rightmost[i] <= r) return data[i];
		if (rightmost[i] < l || leftmost[i] > r) return zero_value;
		return combine(getValue(l, r, i + i), getValue(l, r, i + i + 1));
	}

	void set(TCoord x, T value) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = value;
		i /= 2;

		while (i) {
			data[i] = combine(data[i + i], data[i + i + 1]);
			i /= 2;
		}
	}

	void change(TCoord x, function<T(T)> changer) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = changer(data[i]);
		i /= 2;

		while (i) {
			data[i] = combine(data[i + i], data[i + i + 1]);
			i /= 2;
		}
	}
};

const double PI = atan2(0, -1);

int main() {
	srand (time(NULL));
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	fixed(cout); cout << setprecision(10);
	fixed(cerr); cerr << setprecision(10);

	next(int, n);
	next(int, m);

	Tree<matrix, int> segment_tree(n, [] (matrix a, matrix b) { return a * b; }, matrix(), matrix(1));

	while (m --> 0) {
		next(int, t);
		next(int, i); i--;
		next(int, x);

		matrix change;
		if (t == 1) {
			change.mx[0][2] = x;
			segment_tree.change(i, [&change] (matrix m) { return m * change ; });
		} else {
			double a = x / 180.0 * PI;
			change.mx[0][0] = cos(a);
			change.mx[0][1] = sin(a);
			change.mx[1][0] = -sin(a);
			change.mx[1][1] = cos(a);
			segment_tree.change(i, [&change] (matrix m) { return change * m ; });
		}

		auto res = segment_tree.getValue(0, n - 1);

		printf("%.17lf %.17lf\n", res.mx[0][2], res.mx[1][2]);
	}
}


#include "assert.h"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

using namespace std;

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

template<typename T> inline void minimize(T &a, T b) { a = std::min(a, b); }
template<typename T> inline void maximize(T &a, T b) { a = std::max(a, b); }

template<typename T> inline void swap(pair<T, T> &p) { swap(p.first , p.second ); }

#define all(v) v.begin(),v.end()

#define endl '\n'
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define next(t, i) argument_type<void(t)>::type i; cin >> i;

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) { if (i) os << ' '; os << v[i]; } os << endl; return os; }
template <typename T1, typename T2> ostream& operator << (ostream& os, const vector<pair<T1, T2>> &v) { for (int i = 0 ; i < v.size() ; i++) { os << v[i] << endl; } return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, const pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

struct matrix {
	vector<vector<double>> mx;

	matrix() {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
	}

	matrix(int i) {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
		mx[0][2] = 1;
	}

	void print(ostream& os) {
		FOR (i, 0, 3) {
			FOR (j, 0, 3) os << mx[i][j] << ' ';
			os << endl;
		}
	}

	matrix operator *(matrix &other) {
		matrix res = matrix();
		FOR (i, 0, 3) FOR (j, 0, 3) res.mx[i][j] = 0;
		FOR (i, 0, 3) FOR (j, 0, 3) FOR (k, 0, 3) res.mx[i][j] += mx[i][k] * other.mx[k][j];

		// cerr << "1 --- " << endl;

		// print(cerr);

		// cerr << "2 ---- " << endl;
		// other.print(cerr);
		// cerr  << " result : " << endl;
		// res.print(cerr);
		// cerr << "----" << endl;

		return res;
	}
};

ostream& operator << (ostream& os, const matrix &m) {
	FOR (i, 0, 3) {
		FOR (j, 0, 3) os << m.mx[i][j] << ' ';
		os << endl;
	}
	return os;
}

template <typename T, typename TCoord>
struct Tree {
	int gp2(int n) {
		int x = 1;
		while (x < n) x += x;
		return x;
	}

	int n;
	T zero_value;
	vector<T> data;
	vector<TCoord> leftmost;
	vector<TCoord> rightmost;
	function<T(T, T)> combine;

	void init(function<T(T,T)> combine, T zero_value) {
		this->combine = combine;
		this->zero_value = zero_value;
		for (int i = n - 1 ; i ; i--) data[i] = combine(data[i + i] , data[i + i + 1]), leftmost[i] = leftmost[i + i], rightmost[i] = rightmost[i + i + 1];
	}

	void init_plain_coord() {
		leftmost = rightmost = vector<TCoord>(n + n, (TCoord) 1e20);
		for (int i = 0 ; i < n ; i++) leftmost[n + i] = rightmost[n + i] = i;
	}

	Tree() { }

	Tree(int n, function<T(T,T)> combine, T zero_value) {
		this->n = n = gp2(n);
		data.assign(n + n, zero_value);

		init_plain_coord();
		init(combine, zero_value);
	}

	Tree(vector<T> &v, function<T(T,T)> combine, T zero_value) {
		n = gp2(v.size());
		data.assign(n + n, zero_value);
		for (int i = 0 ; i < v.size() ; i++) data[n + i] = v[i];

		init_plain_coord();
		init(combine, zero_value);
	}

	T getValue(TCoord l, TCoord r, int i = 1) {
		if (leftmost[i] >= l && rightmost[i] <= r) return data[i];
		if (rightmost[i] < l || leftmost[i] > r) return zero_value;
		return combine(getValue(l, r, i + i), getValue(l, r, i + i + 1));
	}

	void set(TCoord x, T value) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = value;
		i /= 2;

		while (i) {
			data[i] = combine(data[i + i], data[i + i + 1]);
			i /= 2;
		}
	}

	void change(TCoord x, function<T(T)> changer) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = changer(data[i]);
		i /= 2;

		while (i) {
			data[i] = combine(data[i + i], data[i + i + 1]);
			i /= 2;
		}
	}
};

const double PI = atan2(0, -1);

int main() {
	srand (time(NULL));
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	fixed(cout); cout << setprecision(10);
	fixed(cerr); cerr << setprecision(10);

	next(int, n);
	next(int, m);

	Tree<matrix, int> segment_tree(n, [] (matrix a, matrix b) { return a * b; }, matrix());
	FOR (i, 0, n) segment_tree.set(i, matrix(1));

	while (m --> 0) {
		next(int, t);
		next(int, i); i--;
		next(int, x);

		matrix change;
		if (t == 1) {
			change.mx[0][2] = x;
			segment_tree.change(i, [&change] (matrix m) { return m * change ; });
		} else {
			double a = x / 180.0 * PI;
			change.mx[0][0] = cos(a);
			change.mx[0][1] = sin(a);
			change.mx[1][0] = -sin(a);
			change.mx[1][1] = cos(a);
			segment_tree.change(i, [&change] (matrix m) { return change * m ; });
		}

		auto res = segment_tree.getValue(0, n - 1);

		printf("%.17lf %.17lf\n", res.mx[0][2], res.mx[1][2]);
	}
}


#include "assert.h"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

using namespace std;

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

template<typename T> inline void minimize(T &a, T b) { a = std::min(a, b); }
template<typename T> inline void maximize(T &a, T b) { a = std::max(a, b); }

template<typename T> inline void swap(pair<T, T> &p) { swap(p.first , p.second ); }

#define all(v) v.begin(),v.end()

#define endl '\n'
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define next(t, i) argument_type<void(t)>::type i; cin >> i;

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) { if (i) os << ' '; os << v[i]; } os << endl; return os; }
template <typename T1, typename T2> ostream& operator << (ostream& os, const vector<pair<T1, T2>> &v) { for (int i = 0 ; i < v.size() ; i++) { os << v[i] << endl; } return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, const pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

struct matrix {
	vector<vector<double>> mx;

	matrix() {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
	}

	matrix(int i) {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
		mx[0][2] = 1;
	}

	void print(ostream& os) {
		FOR (i, 0, 3) {
			FOR (j, 0, 3) os << mx[i][j] << ' ';
			os << endl;
		}
	}

	matrix operator *(matrix &other) {
		matrix res = matrix();
		FOR (i, 0, 3) FOR (j, 0, 3) res.mx[i][j] = 0;
		FOR (i, 0, 3) FOR (j, 0, 3) FOR (k, 0, 3) res.mx[i][j] += mx[i][k] * other.mx[k][j];

		// cerr << "1 --- " << endl;

		// print(cerr);

		// cerr << "2 ---- " << endl;
		// other.print(cerr);
		// cerr  << " result : " << endl;
		// res.print(cerr);
		// cerr << "----" << endl;

		return res;
	}
};

ostream& operator << (ostream& os, const matrix &m) {
	FOR (i, 0, 3) {
		FOR (j, 0, 3) os << m.mx[i][j] << ' ';
		os << endl;
	}
	return os;
}

template <typename T, typename TCoord>
struct Tree {
	int gp2(int n) {
		int x = 1;
		while (x < n) x += x;
		return x;
	}

	int n;
	T zero_value;
	vector<T> data;
	vector<TCoord> leftmost;
	vector<TCoord> rightmost;
	function<T(T, T)> combine;

	void init(function<T(T,T)> combine, T zero_value) {
		this->combine = combine;
		this->zero_value = zero_value;
		for (int i = n - 1 ; i ; i--) data[i] = combine(data[i + i] , data[i + i + 1]), leftmost[i] = leftmost[i + i], rightmost[i] = rightmost[i + i + 1];
	}

	void init_plain_coord() {
		leftmost = rightmost = vector<TCoord>(n + n, (TCoord) 1e20);
		for (int i = 0 ; i < n ; i++) leftmost[n + i] = rightmost[n + i] = i;
	}

	void init_compressed_coord(vector<TCoord> &coords) {
		leftmost = rightmost = vector<TCoord>(n + n, (TCoord) 1e20);
		for (int i = 0 ; i < coords.size() ; i++) leftmost[n + i] = rightmost[n + i] = coords[i];
	}

	Tree() { }

	Tree(int n, function<T(T,T)> combine, T zero_value) {
		this->n = n = gp2(n);
		data.assign(n + n, zero_value);

		init_plain_coord();
		init(combine, zero_value);
	}

	Tree(vector<T> &v, function<T(T,T)> combine, T zero_value) {
		n = gp2(v.size());
		data.assign(n + n, zero_value);
		for (int i = 0 ; i < v.size() ; i++) data[n + i] = v[i];

		init_plain_coord();
		init(combine, zero_value);
	}

	Tree(vector<TCoord> coords, function<T(T, T)> combine, T zero_value, bool dummy) {
		sort(coords.begin(), coords.end());
		coords.resize(unique(coords.begin(), coords.end()) - coords.begin());
		n = gp2(coords.size());
		data.assign(n + n, zero_value);

		init_compressed_coord(coords);
		init(combine, zero_value);
	}

	T getValue(TCoord l, TCoord r, int i = 1) {
		if (leftmost[i] >= l && rightmost[i] <= r) return data[i];
		if (rightmost[i] < l || leftmost[i] > r) return zero_value;
		return combine(getValue(l, r, i + i), getValue(l, r, i + i + 1));
	}

	void set(TCoord x, T value) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = value;
		i /= 2;

		while (i) {
			data[i] = combine(data[i + i], data[i + i + 1]);
			i /= 2;
		}
	}

	void change(TCoord x, function<T(T)> changer) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = changer(data[i]);
		i /= 2;

		while (i) {
			data[i] = combine(data[i + i], data[i + i + 1]);
			i /= 2;
		}
	}
};

const double PI = atan2(0, -1);

int main() {
	srand (time(NULL));
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	fixed(cout); cout << setprecision(10);
	fixed(cerr); cerr << setprecision(10);

	next(int, n);
	next(int, m);

	Tree<matrix, int> segment_tree(n, [] (matrix a, matrix b) { return a * b; }, matrix());
	FOR (i, 0, n) segment_tree.set(i, matrix(1));

	while (m --> 0) {
		next(int, t);
		next(int, i); i--;
		next(int, x);

		matrix change;
		if (t == 1) {
			change.mx[0][2] = x;
		} else {
			double a = x / 180.0 * PI;
			change.mx[0][0] = cos(a);
			change.mx[0][1] = sin(a);
			change.mx[1][0] = -sin(a);
			change.mx[1][1] = cos(a);
		}
		segment_tree.change(i, [&change] (matrix m) { return change * m; });

		auto res = segment_tree.getValue(0, n - 1);

		printf("%.17lf %.17lf\n", res.mx[0][2], res.mx[1][2]);
	}
}


#include "assert.h"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

using namespace std;

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

template<typename T> inline void minimize(T &a, T b) { a = std::min(a, b); }
template<typename T> inline void maximize(T &a, T b) { a = std::max(a, b); }

template<typename T> inline void swap(pair<T, T> &p) { swap(p.first , p.second ); }

#define all(v) v.begin(),v.end()

#define endl '\n'
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define next(t, i) argument_type<void(t)>::type i; cin >> i;

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) { if (i) os << ' '; os << v[i]; } os << endl; return os; }
template <typename T1, typename T2> ostream& operator << (ostream& os, const vector<pair<T1, T2>> &v) { for (int i = 0 ; i < v.size() ; i++) { os << v[i] << endl; } return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, const pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

struct matrix {
	vector<vector<double>> mx;

	matrix() {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
	}

	matrix(int i) {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
		mx[0][2] = 1;
	}

	matrix operator *(matrix &other) {
		matrix res = matrix();
		FOR (i, 0, 2) FOR (j, 0, 3) res.mx[i][j] = 0;
		FOR (i, 0, 2) FOR (j, 0, 3) FOR (k, 0, 3) res.mx[i][j] += mx[i][k] * other.mx[k][j];
		return res;
	}
};

void mult_into(const matrix &m1, const matrix &m2, matrix &res) {
	FOR (i, 0, 3) FOR (j, 0, 3) res.mx[i][j] = 0;
	FOR (i, 0, 3) FOR (j, 0, 3) FOR (k, 0, 3) res.mx[i][j] += m1.mx[i][k] * m2.mx[k][j];
}

template <typename T, typename TCoord>
struct Tree {
	int gp2(int n) {
		int x = 1;
		while (x < n) x += x;
		return x;
	}

	int n;
	T zero_value;
	vector<T> data;
	vector<TCoord> leftmost;
	vector<TCoord> rightmost;
	function<T(T&, T&)> combine;

	void init(function<T(T&,T&)> combine, T zero_value) {
		this->combine = combine;
		this->zero_value = zero_value;
		for (int i = n - 1 ; i ; i--)
			mult_into(data[i + i], data[i + i + 1], data[i]),
			leftmost[i] = leftmost[i + i], rightmost[i] = rightmost[i + i + 1];
	}

	void init_plain_coord() {
		leftmost = rightmost = vector<TCoord>(n + n, (TCoord) 1e20);
		for (int i = 0 ; i < n ; i++) leftmost[n + i] = rightmost[n + i] = i;
	}

	Tree() { }

	Tree(int n, function<T(T&,T&)> combine, T zero_value, T init_value) {
		int n1 = n;
		this->n = n = gp2(n);
		data.assign(n + n, zero_value);
		FOR (i, 0, n1) data[n + i] = init_value;

		init_plain_coord();
		init(combine, zero_value);
	}

	T getValue(TCoord l, TCoord r, int i = 1) {
		if (leftmost[i] >= l && rightmost[i] <= r) return data[i];
		if (rightmost[i] < l || leftmost[i] > r) return zero_value;

		auto val1 = getValue(l, r, i + i);
		auto val2 = getValue(l, r, i + i + 1);

		return combine(val1, val2);
	}

	void update_up(int i) {
		i /= 2;

		while (i) {
			mult_into(data[i + i], data[i + i + 1], data[i]);
			i /= 2;
		}
	}

	void set(TCoord x, T value) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = value;
		update_up(i);
	}

	void change(TCoord x, function<T(T)> changer) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = changer(data[i]);
		update_up(i);
	}
};

const double PI = atan2(0, -1);

int main() {
	srand (time(NULL));
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	fixed(cout); cout << setprecision(10);
	fixed(cerr); cerr << setprecision(10);

	next(int, n);
	next(int, m);

	Tree<matrix, int> segment_tree(n, [] (matrix &a, matrix &b) { return a * b; }, matrix(), matrix(1));

	vector<matrix> rotations;

	while (m --> 0) {
		next(int, t);
		next(int, i); i--;
		next(int, x);

		matrix change;
		if (t == 1) {
			change.mx[0][2] = x;
				segment_tree.change(i, [&change] (matrix m) { return m * change; });
			} else {
			while (rotations.size() <= x) {
				double a = rotations.size() / 180.0 * PI;
				rotations.push_back(matrix());
				rotations.back().mx[0][0] = cos(a);
				rotations.back().mx[0][1] = sin(a);
				rotations.back().mx[1][0] = -sin(a);
				rotations.back().mx[1][1] = cos(a);
			}

			change = rotations[x];
			segment_tree.change(i, [&change] (matrix m) { return change * m ; });
		}

		printf("%.17lf %.17lf\n", segment_tree.data[1].mx[0][2], segment_tree.data[1].mx[1][2]);
	}
}


#include "assert.h"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

using namespace std;

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

template<typename T> inline void minimize(T &a, T b) { a = std::min(a, b); }
template<typename T> inline void maximize(T &a, T b) { a = std::max(a, b); }

template<typename T> inline void swap(pair<T, T> &p) { swap(p.first , p.second ); }

#define all(v) v.begin(),v.end()

#define endl '\n'
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define next(t, i) argument_type<void(t)>::type i; cin >> i;

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) { if (i) os << ' '; os << v[i]; } os << endl; return os; }
template <typename T1, typename T2> ostream& operator << (ostream& os, const vector<pair<T1, T2>> &v) { for (int i = 0 ; i < v.size() ; i++) { os << v[i] << endl; } return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, const pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

struct matrix {
	vector<vector<double>> mx;

	matrix() {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
	}

	matrix(int i) {
		mx = vector<vector<double>>(3, vector<double>(3));
		mx[0][0] = mx[1][1] = mx[2][2] = 1;
		mx[0][2] = 1;
	}

	void print(ostream& os) {
		FOR (i, 0, 3) {
			FOR (j, 0, 3) os << mx[i][j] << ' ';
			os << endl;
		}
	}

	matrix operator *(matrix &other) {
		matrix res = matrix();
		FOR (i, 0, 3) FOR (j, 0, 3) res.mx[i][j] = 0;
		FOR (i, 0, 3) FOR (j, 0, 3) FOR (k, 0, 3) res.mx[i][j] += mx[i][k] * other.mx[k][j];

		// cerr << "1 --- " << endl;

		// print(cerr);

		// cerr << "2 ---- " << endl;
		// other.print(cerr);
		// cerr  << " result : " << endl;
		// res.print(cerr);
		// cerr << "----" << endl;

		return res;
	}
};

ostream& operator << (ostream& os, const matrix &m) {
	FOR (i, 0, 3) {
		FOR (j, 0, 3) os << m.mx[i][j] << ' ';
		os << endl;
	}
	return os;
}

template <typename T, typename TCoord>
struct Tree {
	int gp2(int n) {
		int x = 1;
		while (x < n) x += x;
		return x;
	}

	int n;
	T zero_value;
	vector<T> data;
	vector<TCoord> leftmost;
	vector<TCoord> rightmost;
	function<T(T, T)> combine;

	void init(function<T(T,T)> combine, T zero_value) {
		this->combine = combine;
		this->zero_value = zero_value;
		for (int i = n - 1 ; i ; i--) data[i] = combine(data[i + i] , data[i + i + 1]), leftmost[i] = leftmost[i + i], rightmost[i] = rightmost[i + i + 1];
	}

	void init_plain_coord() {
		leftmost = rightmost = vector<TCoord>(n + n, (TCoord) 1e20);
		for (int i = 0 ; i < n ; i++) leftmost[n + i] = rightmost[n + i] = i;
	}

	void init_compressed_coord(vector<TCoord> &coords) {
		leftmost = rightmost = vector<TCoord>(n + n, (TCoord) 1e20);
		for (int i = 0 ; i < coords.size() ; i++) leftmost[n + i] = rightmost[n + i] = coords[i];
	}

	Tree() { }

	Tree(int n, function<T(T,T)> combine, T zero_value) {
		this->n = n = gp2(n);
		data.assign(n + n, zero_value);

		init_plain_coord();
		init(combine, zero_value);
	}

	Tree(vector<T> &v, function<T(T,T)> combine, T zero_value) {
		n = gp2(v.size());
		data.assign(n + n, zero_value);
		for (int i = 0 ; i < v.size() ; i++) data[n + i] = v[i];

		init_plain_coord();
		init(combine, zero_value);
	}

	Tree(vector<TCoord> coords, function<T(T, T)> combine, T zero_value, bool dummy) {
		sort(coords.begin(), coords.end());
		coords.resize(unique(coords.begin(), coords.end()) - coords.begin());
		n = gp2(coords.size());
		data.assign(n + n, zero_value);

		init_compressed_coord(coords);
		init(combine, zero_value);
	}

	T getValue(TCoord l, TCoord r, int i = 1) {
		if (leftmost[i] >= l && rightmost[i] <= r) return data[i];
		if (rightmost[i] < l || leftmost[i] > r) return zero_value;
		return combine(getValue(l, r, i + i), getValue(l, r, i + i + 1));
	}

	void set(TCoord x, T value) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = value;
		i /= 2;

		while (i) {
			data[i] = combine(data[i + i], data[i + i + 1]);
			i /= 2;
		}
	}

	void change(TCoord x, function<T(T)> changer) {
		int i = 1;
		while (i < n) {
			i += i;
			if (rightmost[i] < x) i++;
		}
		data[i] = changer(data[i]);
		i /= 2;

		while (i) {
			data[i] = combine(data[i + i], data[i + i + 1]);
			i /= 2;
		}
	}
};

const double PI = atan2(0, -1);

int main() {
	srand (time(NULL));
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	fixed(cout); cout << setprecision(10);
	fixed(cerr); cerr << setprecision(10);

	next(int, n);
	next(int, m);

	Tree<matrix, int> segment_tree(n, [] (matrix a, matrix b) { return a * b; }, matrix());
	FOR (i, 0, n) segment_tree.set(i, matrix(1));

	while (m --> 0) {
		next(int, t);
		next(int, i); i--;
		next(int, x);

		matrix change;
		if (t == 1) {
			change.mx[0][2] = x;
		} else {
			double a = x / 180.0 * PI;
			change.mx[0][0] = cos(a);
			change.mx[0][1] = sin(a);
			change.mx[1][0] = -sin(a);
			change.mx[1][1] = cos(a);
		}
		segment_tree.change(i, [&change] (matrix m) { return change * m; });

		auto res = segment_tree.getValue(0, n - 1);

		printf("%.17g %.17g\n", res.mx[0][2], res.mx[1][2]);
	}
}