#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main()
{
    long n,i,j,k,flag=0;
    char a[100];
    scanf("%ld",&n);
    for(j=0;j<=n/7;j++)
    {
        for(i=0;i<=n/4;i++)
        {
            if(7*j+4*i==n)
            {
              for(k=0;k<i;k++)
              {
                  a[k]='4';
              }
              for(k=i;k<i+j;k++)
              {
                  a[k]='7';
              }
              a[i+j]='\0';
              flag=1;
              break;
            }

        }
    }
    if(flag==0)
    {
        printf("-1");
    }
    printf("%s",a);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main()
{
    long n,i,j,k,flag=0;
    scanf("%ld",&n);
    for(j=0;j<=n/7;j++)
    {
        for(i=0;i<=n/4;i++)
        {
            if(7*j+4*i==n)
            {
              for(k=0;k<i;k++)
              {
                  printf("4");
              }
              for(k=i;k<i+j;k++)
              {
                  printf("7");
              }

              flag=1;
              break;
            }

        }
    }
    if(flag==0)
    {
        printf("-1");
    }

    return 0;
}


#include<stdio.h>
int main()
{  int n,i,j,k,flag,sum;
    int s4,s7;
	scanf("%d",&n)  ;
    s4=n/4; s7=n/7;
    for(i=0;i<=s4;i++)
    {
        for(j=0;j<=s7;j++)
        {
            if(i*4+j*7==n)
            {
                flag=1;
                break;
            }
        }
        if(flag)  break;
    }
    if(!flag)
    {
    	printf("-1");
	}
    else
    {
        for(k=1;k<=i;k++)
            printf("4");
        for(k=1;k<=j;k++)
            printf("7");
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int n, a, b, aMin = -1, bMin = -1, i;
    scanf("%I64d", &n);
    for (b = 0; (b * 7) <= n; b++){
        a = (n - b * 7);
        if (a % 4 == 0){
            a /= 4;
            if (aMin == -1){
                aMin = a; bMin = b;
            }else if ((a + b) < (aMin + bMin)){
                aMin = a; bMin = b;
            }
        }else if ((!b) && (n % 4 == 0)) {
            a /= 4;
            if (aMin == -1){
                aMin = a; bMin = b;
            }else if ((a + b) < (aMin + bMin)){
                aMin = a; bMin = b;
            }
        }
    }
    if (aMin == -1) printf("-1\n");
    else {
        for (i = 0; i < aMin; i++) printf("4");
        for (i = 0; i < bMin; i++) printf("7");
        printf("\n");
    }
    return 0;
}


/*
 * =====================================================================================
 *
 *       Filename:  6.c
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  05/14/2013 10:12:29 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Devansh T Shah (@d),
 *        Company:  IIIT Hyd
 *
 * =====================================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define si(n) scanf("%d",&n)
#define rep(i,n) for(i=0;i<n;i++)
#define REP(i,a,b) for(i=a;i<b;i++)
#define nl printf("\n")
#define sp printf(" ")
#define dbg(n) printf(" #n -- > %d\n",n)
#define dbg2(m,n) printf(" #m -- > %d #n --> %d\n",m,n)
#define pi(n) printf("%d",n)
#define pll(n) printf("%lld",n)
#define sll(n) scanf("%lld",&n)
#define ss(s) scanf("%s",s)
#define ps(s) printf("%s",s)
typedef long long LL;

int main() {
    int n,i,p,q;
    scanf("%d",&n);
    int flag = 1;
    for(i = n / 7; i >= 0; i--){
	int j = n - i * 7;
	if(j % 4 == 0){
	    flag = 0;
	    for(p = 0; p < j / 4; p++)        printf("4");
	    for(q = 0; q < i; q++)    	  printf("7");
	    printf("\n");
	    break;
	}
    }
    if(flag==1)     printf("-1\n");
    return 0;
}


// Lucky Sum of Digits

#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[1000001] = "";
	int n,n2,x,y,i;
	scanf("%d",&n);
	n2 = (n/7)*7;
	while(n2>=0)
	{
		if((n-n2)%4==0)
			break;
		else
			n2 = n2-7;
	}
	if(n2<0)
		printf("-1\n");
	else
	{
		y = n2/7;
		x = (n-n2)/4;

		for(i = 0;i<x;i++)
			strcat(s,"4");
		for(i = 0;i<y;i++)
			strcat(s,"7");

		printf("%s\n",s);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INFINITY 1000000000

int main ()
{
	int N, X, Y;
	scanf("%d",&N);
	int resX = INFINITY;
	int resY = INFINITY;
	for (X = 0; (4*X) <= N; X++)
	{
		if (!((N-4*X) % 7))
		{
			Y = (N-4*X) / 7;
			if (((X+Y) < (resX+resY)) || (((X+Y) < (resX+resY)) && (X < resX)))
			{
				resX = X;
				resY = Y;
			}
		}
	}
	if (resX == INFINITY) printf("-1\n");
	else
	{
		for (X = 0; X < resX; X++) printf("4");
		for (Y = 0; Y < resY; Y++) printf("7");
		printf("\n");
	}
	return 0;
}


import java.util.*;

public class Trying
{
    public static void main (String[] args)
    {
        Scanner enter = new Scanner(System.in);
        int n = enter.nextInt(), lic = 1, pos = 0,
        fornow = -1, loc = 0, max = 0, min = Integer.MAX_VALUE;
        String num = new String ();
        for(int i = n ; i >= n/2 ; i--)
        {
            if(i % 7 == 0 && (n-i) % 4 == 0)
            {
                for(int j = 0 ; j < (n-i)/4 ; j++)
                    System.out.print(4);
                for(int j = 0 ; j < i/7 ; j++)
                    System.out.print(7);
                System.exit(0);
            }
        }
            if(n % 4 == 0)
            {
                for(int j = 0 ; j < n/4 ; j++)
                    System.out.print(4);
                System.exit(0);
            }

        System.out.println(-1);
    }
}


import java.util.*;

public class Trying
{
    public static void main (String[] args)
    {
        Scanner enter = new Scanner(System.in);
        int n = enter.nextInt(), lic = 1, lucky[] = new int [n], pos = 0;
        String num = new String ();
            for(int i = n ; i > 0 ; i--)
            {
                num = "";
                num += i;
                for(int j = 0 ; j < num.length() ; j++)
                {
                    lic = 1;
                    if(num.charAt(j) != '4' && num.charAt(j) != '7')
                        {lic = 0;break;}
                    if(lic == 1){lucky[pos++] = i; n-=i; i=n+1;}
                }
            }
        if(n != 0)System.out.println(-1);
        else
        {
            for(int i = 0 ; i < pos ; i++)
                System.out.print(lucky[i]);
        }
    }
}


import java.util.*;

public class Trying
{
    public static void main (String[] args)
    {
        Scanner enter = new Scanner(System.in);
        int n = enter.nextInt(), lic = 1, lucky[] = new int [n], pos = 0;
        String num = new String ();
            for(int i = n ; i > 0 ; i--)
            {
                num = "";
                num += i;
                for(int j = 0 ; j < num.length() ; j++)
                {
                    lic = 1;
                    if(num.charAt(j) != '4' && num.charAt(j) != '7')
                        {lic = 0;break;}
                    if(lic == 1){lucky[pos++] = i; n-=i; i=n+1;}
                }
            }
        if(n != 0)System.out.println(-1);
        else
        {
            for(int i = pos-1 ; i >= 0 ; i--)
                System.out.print(lucky[i]);
        }
    }
}


import java.util.*;

public class Trying
{
    public static void main (String[] args)
    {
        Scanner enter = new Scanner(System.in);
        int n = enter.nextInt(), lic = 1, lucky[][] = new int [n][n], pos = 0,
        fornow = -1, loc = 0, max = 0, min = Integer.MAX_VALUE;
        String num = new String ();
        for(int i = n ; i >= n/2 ; i--)
        {
            pos = 0;
            if(i % 7 == 0 && (n-i) % 4 == 0)
            {
                fornow++;
                for(int j = 0 ; j < (n-i)/4 ; j++)
                    lucky[fornow][pos++] = 4;
                for(int j = 0 ; j < i/7 ; j++)
                    lucky[fornow][pos++] = 7;
            }
            else if(i % 4 == 0 && (n-i) % 7 == 0)
            {
                fornow++;
                for(int j = 0 ; j < (n-i)/7 ; j++)
                    lucky[fornow][pos++] = 7;
                for(int j = 0 ; j < i/4 ; j++)
                    lucky[fornow][pos++] = 4;
            }
            if(min > pos && pos != 0){min = pos; loc = fornow;}
        }
        if(fornow == -1)System.out.println(-1);
        else
        {
            for(int i = 0 ; i < min ; i++)
                System.out.print(lucky[loc][i]);
        }
    }
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class LuckySumOfDigits {
	static int mod = 1000000007;

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

	public static void main(String[] args) throws IOException {
		Reader in = new Reader();
		int n, i, t;
		n = in.nextInt();
		StringBuilder ans = new StringBuilder();
		if (n == 4) {
			System.out.println("4");
			return;
		}
		if (n == 7) {
			System.out.println("7");
			return;
		}
		if (n / 10 == 0 && (n != 4 || n != 7)) {
			System.out.println("-1");
			return;
		}

		boolean flag = false;
		int r = n % 7, four = 0;
		int sev = n / 7, x = n, w = sev * 7;
		while (w > 0) {
			if (r % 4 == 0) {
				flag = true;
				for (i = 0; i < r / 4; i++)
					ans.append("4");
				for (i = 0; i < sev; i++)
					ans.append("7");
				System.out.println(ans);
				return;
			}
			r += 7;
			sev--;
			w -= 7;
//			if (r % 4 == 0) {
//				flag = true;
//				for (i = 0; i < r / 4; i++)
//					ans.append("4");
//				for (i = 0; i < sev; i++)
//					ans.append("7");
//				System.out.println(ans);
//				return;
//			}
			// System.out.println(r + " " + sev);
		}
		if (!flag)
			System.out.println("-1");
	}
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class LuckySumOfDigits {
	static int mod = 1000000007;

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

	public static void main(String[] args) throws IOException {
		Reader in = new Reader();
		int n, i, t;
		n = in.nextInt();
		StringBuilder ans = new StringBuilder();
		if (n / 10 == 0 && (n != 4 || n != 7)) {
			System.out.println("-1");
			return;
		}
		if (n == 7) {
			System.out.println("7");
			return;
		}
		if (n == 4) {
			System.out.println("4");
			return;
		}
		boolean flag = false;
		int r = n % 7, four = 0;
		int sev = n / 7, x = n, w = sev * 7;
		while (w > 0) {
			if (r % 4 == 0) {
				flag = true;
				for (i = 0; i < r / 4; i++)
					ans.append("4");
				for (i = 0; i < sev; i++)
					ans.append("7");
				System.out.println(ans);
				return;
			}
			r += 7;
			sev--;
			w -= 7;
//			if (r % 4 == 0) {
//				flag = true;
//				for (i = 0; i < r / 4; i++)
//					ans.append("4");
//				for (i = 0; i < sev; i++)
//					ans.append("7");
//				System.out.println(ans);
//				return;
//			}
			// System.out.println(r + " " + sev);
		}
		if (!flag)
			System.out.println("-1");
	}
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class LuckySumOfDigits {
	static int mod = 1000000007;

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

	public static void main(String[] args) throws IOException {
		Reader in = new Reader();
		int n, i, t;
		n = in.nextInt();
		StringBuilder ans = new StringBuilder();
		if (n == 4) {
			System.out.println("4");
			return;
		}
		if (n == 7) {
			System.out.println("7");
			return;
		}
//		if (n / 10 == 0 && (n != 4 || n != 7)) {
//			System.out.println("-1");
//			return;
//		}

		boolean flag = false;
		int r = n % 7, four = 0;
		int sev = n / 7, x = n, w = sev * 7;
		while (w >= 0) {
			if (r % 4 == 0) {
				flag = true;
				for (i = 0; i < r / 4; i++)
					ans.append("4");
				for (i = 0; i < sev; i++)
					ans.append("7");
				System.out.println(ans);
				return;
			}
			r += 7;
			sev--;
			w -= 7;
//			if (r % 4 == 0) {
//				flag = true;
//				for (i = 0; i < r / 4; i++)
//					ans.append("4");
//				for (i = 0; i < sev; i++)
//					ans.append("7");
//				System.out.println(ans);
//				return;
//			}
			// System.out.println(r + " " + sev);
		}
		if (!flag)
			System.out.println("-1");
	}
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class LuckySumOfDigits {
	static int mod = 1000000007;

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

	public static void main(String[] args) throws IOException {
		Reader in = new Reader();
		int n, i, t;
		n = in.nextInt();
		StringBuilder ans = new StringBuilder();
		if (n == 4) {
			System.out.println("4");
			return;
		}
		if (n == 7) {
			System.out.println("7");
			return;
		}
		if (n / 10 == 0 && (n != 4 || n != 7)) {
			System.out.println("-1");
			return;
		}

		boolean flag = false;
		int r = n % 7, four = 0;
		int sev = n / 7, x = n, w = sev * 7;
		while (w >= 0) {
			if (r % 4 == 0) {
				flag = true;
				for (i = 0; i < r / 4; i++)
					ans.append("4");
				for (i = 0; i < sev; i++)
					ans.append("7");
				System.out.println(ans);
				return;
			}
			r += 7;
			sev--;
			w -= 7;
//			if (r % 4 == 0) {
//				flag = true;
//				for (i = 0; i < r / 4; i++)
//					ans.append("4");
//				for (i = 0; i < sev; i++)
//					ans.append("7");
//				System.out.println(ans);
//				return;
//			}
			// System.out.println(r + " " + sev);
		}
		if (!flag)
			System.out.println("-1");
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vikash Kumar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Codeforces solver = new Codeforces();
        solver.solve(1, in, out);
        out.close();
    }

    static class Codeforces {
        public void solve(int testNumber, InputReader in, OutputWriter out) throws IndexOutOfBoundsException {
            int n = in.ni();
            StringBuilder sub = new StringBuilder();
            boolean flag = false;
            while (n > 0) {
                if (n % 4 == 0 && n >= 4) {
                    n -= 4;
                    sub.append(4);
                } else if (n % 4 == 3 && n >= 7) {
                    n -= 7;
                    sub.append(7);
                } else {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                out.println(-1);
            } else {
                char[] arr = sub.toString().toCharArray();
                Arrays.sort(arr);
                int num1 = 0;
                int num2 = 0;
                for (char e : arr) {
                    if (e == '4') num1++;
                    else num2++;
                }
                int count = num1 / 7;
                for (int i = 0; i < num1 % 7; i++) {
                    out.print(4);
                }
                for (int i = 0; i < 4 * count + num2; i++) {
                    out.print(7);
                }
            }
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String n() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(n());
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vikash Kumar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Codeforces solver = new Codeforces();
        solver.solve(1, in, out);
        out.close();
    }

    static class Codeforces {
        public void solve(int testNumber, InputReader in, OutputWriter out) throws IndexOutOfBoundsException {
            int n = in.ni();
            long a = 0, b = 0;
            boolean flag = false;
            for (int i = 0; i < n; i++) {
                long num = fun(i, n);
                if (num < 0) {
                    break;
                } else {
                    if ((num * 4 + i * 7) == n) {
                        flag = true;
                        a = num;
                        b = i;
                        //break;
                    }
                }
            }
            if (!flag) {
                out.println(-1);
            } else {
                //out.println(a + " " + b);
                int nn = (int) a / 7;
                for (int i = 0; i < (int) a % 7; i++) {
                    out.print(4);
                }
                for (int i = 0; i < 4 * nn + (int) b; i++) {
                    out.print(7);
                }
            }
        }

        long fun(int b, int n) {
            return ((long) n - (long) b * 7l) / 4l;
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String n() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(n());
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vikash Kumar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Codeforces solver = new Codeforces();
        solver.solve(1, in, out);
        out.close();
    }

    static class Codeforces {
        public void solve(int testNumber, InputReader in, OutputWriter out) throws IndexOutOfBoundsException {
            int n = in.ni();
            long a = 0, b = 0;
            boolean flag = false;
            for (int i = 1; i < n; i++) {
                long num = fun(i, n);
                if (num < 0) {
                    break;
                } else {
                    if ((num * 4 + i * 7) == n && num != 0) {
                        flag = true;
                        a = num;
                        b = i;
                        //break;
                    }
                }
            }
            if (!flag) {
                out.println(-1);
            } else {
                //out.println(a + " " + b);
                int nn = (int) a / 7;
                for (int i = 0; i < (int) a % 7; i++) {
                    out.print(4);
                }
                for (int i = 0; i < 4 * nn + (int) b; i++) {
                    out.print(7);
                }
            }
        }

        long fun(int b, int n) {
            return ((long) n - (long) b * 7l) / 4l;
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String n() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(n());
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vikash Kumar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Codeforces solver = new Codeforces();
        solver.solve(1, in, out);
        out.close();
    }

    static class Codeforces {
        public void solve(int testNumber, InputReader in, OutputWriter out) throws IndexOutOfBoundsException {
            int n = in.ni();
            StringBuilder sub = new StringBuilder();
            boolean flag = false;
            while (n > 0) {
                if (n % 4 == 0 && n >= 4) {
                    n -= 4;
                    sub.append(4);
                } else if (n % 4 == 3 && n >= 7) {
                    n -= 7;
                    sub.append(7);
                } else {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                out.println(-1);
            } else {
                char[] arr = sub.toString().toCharArray();
                Arrays.sort(arr);
                for (char e : arr) {
                    out.print(e);
                }
            }
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String n() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(n());
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(char i) {
            writer.print(i);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}


/**
 * ******* Created by K1K on 3/12/19 7:12 AM*******
 */

import java.io.*;
import java.util.*;

public class A109 implements Runnable {

    private static final int MAX = (int) (1E5 + 5);
    private static final int MOD = (int) (1E9 + 7);
    private static final int Inf = (int) (1E9 + 100);
    private void solve() throws IOException {
        int n = reader.nextInt();
        int best = MOD;
        int bx =-1, by =-1;
        for(int i=0;i*4<=n;i++){
            int j = n- 4*i;
            if(j% 7==0){
                int y =  j / 7;
                if(best >= i+y ){
                    best = i+ y;
                    bx = i;
                    by = y;
                }
            }
        }

        if(best == Inf)writer.println("-1");
        else{
            for(int i=0;i<bx;i++)writer.print('4');
            for(int i=0;i<by;i++)writer.print('7');
        }
    }

    public static void main(String[] args) throws IOException {
        try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            new A109().run();
        }
    }

    StandardInput reader;
    PrintWriter writer;

    @Override
    public void run() {
        try {
            reader = new StandardInput();
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

        default int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        default long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        default double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}


/**
 * ******* Created by K1K on 3/12/19 7:12 AM*******
 */

import java.io.*;
import java.util.*;

public class A109 implements Runnable {

    private static final int MAX = (int) (1E5 + 5);
    private static final int MOD = (int) (1E9 + 7);
    private static final int Inf = (int) (1E9 + 100);
    private void solve() throws IOException {
        int n = reader.nextInt();
        int best = Inf;
        int bx =-1, by =-1;
        for(int i=0;i*4<=n;i++){
            int j = n- 4*i;
            if(j% 7==0){
                int y =  j / 7;
                if(best >= i+y ){
                    best = i+ y;
                    bx = i;
                    by = y;
                }
            }
        }

        if(best == Inf)writer.println("-1");
        else{
            for(int i=0;i<bx;i++)writer.print('4');
            for(int i=0;i<by;i++)writer.print('7');
        }
    }

    public static void main(String[] args) throws IOException {
        try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            new A109().run();
        }
    }

    StandardInput reader;
    PrintWriter writer;

    @Override
    public void run() {
        try {
            reader = new StandardInput();
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

        default int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        default long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        default double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}


import java.util.Scanner;

public class ALuckySumOfDigits {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int sum=0;
        String res="";
        do {
            sum+=4;
            res+="4";
        }while((n-sum)%7!=0&& sum<=n);

        while(sum<n) {
            sum+=7;
            res+="7";
        }
        if(sum==n)
            System.out.println(res);
        else
            System.out.println("-1");

    }

}


import java.util.Scanner;

public class ALuckySumOfDigits {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

        for (long i = 0; i < Long.MAX_VALUE/2; i++) {

            if(verif(i+""))
            {
                String ch=i+"";
                int s=0;
                for (int j = 0; j < ch.length(); j++) {
                    s+=Integer.parseInt(ch.charAt(j)+"");
                }
                if(s==n)
                {
                    System.out.println(i);
                    break;
                }
                else
                    if(s>n)
                    {
                        System.out.println("-1");
                        break;
                    }
            }
        }
    }
    private static boolean verif(String ch)
    {
        String c="01235689";
        for (int i = 0; i < ch.length(); i++) {
            if(c.contains(ch.charAt(i)+""))
                return false;
        }
        return true;
    }

}


import java.util.Scanner;

public class ALuckySumOfDigits {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int sum=0;
        String res="";
        do {
            sum+=7;
            res+="7";
        }while((n-sum)%4!=0&& sum<=n);

        while(sum<n) {
            sum+=4;
            res+="4";
        }
        if(sum==n)
            System.out.println(res);
        else
            System.out.println("-1");

    }

}


import java.util.Scanner;

public class ALuckySumOfDigits {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n==7)
            System.out.println("7");
        else
        {
            int sum=0;
            String res="";
            do {
                sum+=4;
                res+="4";
            }while((n-sum)%7!=0&& sum<=n);

            while(sum<n) {
                sum+=7;
                res+="7";
            }
            if(sum==n)
                System.out.println(res);
            else
                System.out.println("-1");
        }

    }

}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int i, x, y, flag, n, t = in.nextInt();
        while (t-- > 0) {
            n = in.nextInt();
            flag = 0;
            for (y = n / 7; y >= 0; y--) {
                if ((n - 7 * y) % 4 != 0)
                    continue;
                x = (n - 7 * y) / 4;
                for (i = 0; i < x; i++)
                    System.out.print(4);
                for (i = 0; i < y; i++)
                    System.out.print(7);
                System.out.println();
                break;
            }
            if (y < 0)
                System.out.println("-1");
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int i, x, y, flag, n;
        n = in.nextInt();
        flag = 0;
        for (y = n / 7; y >= 0; y--) {
            if ((n - 7 * y) % 4 != 0)
                continue;
            x = (n - 7 * y) / 4;
            for (i = 0; i < x; i++)
                System.out.print(4);
            for (i = 0; i < y; i++)
                System.out.print(7);
            System.out.println();
            break;
        }
        if (y < 0)
            System.out.println("-1");
    }
}


import java.util.Scanner;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int n,i,len,sum=0;
	boolean flag=true,flag1=false;
	String str="4";
	n=scan.nextInt();
	len=str.length();
	while(true)
		{
		flag=true;
		sum=0;
		for(i=0;i<len;++i)
			{
			sum+=Integer.parseInt(str.substring(i,i+1));
			if(!(str.substring(i,i+1).equals("4")))
				flag=false;
			}
		if(flag&&sum>n)
			break;
		if(sum==n)
			{
			flag1=true;
			break;
			}
		flag=true;
		for(i=0;i<len;++i)
			if(!(str.substring(i,i+1).equals("7")))
				{
				flag=false;
				break;
				}
		if(flag)
			{
			str="4";
			for(i=0;i<len;++i)
				str+="4";
			}
		else
			{
			for(i=len-1;i>=0;--i)
				if(str.substring(i,i+1).equals("4"))
					{
					str=str.substring(0,i)+"7"+str.substring(i+1,len);
					break;
					}
			}
		len=str.length();
		}
	if(flag1)
		System.out.println(str);
	else
		System.out.println(-1);
	}
}


import java.util.Scanner;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int n,temp,no7=0,no4=0,i;
	boolean flag=false;
	n=scan.nextInt();
	temp=n;
	if(temp%7==0)
		{
		no7=temp/7;
		flag=true;
		}
	else
		{
		while(true)
			{
			if(temp%7==0)
				{
				flag=true;
				break;
				}
			temp-=4;
			++no4;
			if(temp<0)
				break;
			}
		if(flag)
			no7=temp/7;
		}
	if(flag)
		{
		for(i=1;i<=no4;++i)
			System.out.print("4");
		for(i=1;i<=no7;++i)
			System.out.print("7");
		}
	else
		System.out.println(-1);
	}
}


import java.util.Scanner;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int n,num=4,i,sum=0;
	String str;
	boolean flag=true,flag1=false;
	n=scan.nextInt();
	while(true)
	{
	sum=0;
	flag=true;
	str=Integer.toString(num);
	for(i=0;i<str.length();++i)
		{
		sum+=Integer.parseInt(str.substring(i,i+1));
		if((!(str.substring(i,i+1).equals("4")))&&(!(str.substring(i,i+1).equals("7"))))
			flag=false;
		}
	if(flag&&sum>n)
		break;
	if(flag&&sum==n)
		{
		flag1=true;
		break;
		}
	++num;
	}
	if(flag1)
		System.out.println(num);
	else
		System.out.println(-1);
	}
}


import java.util.Scanner;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int n,i,len,sum=0;
	boolean flag=true,flag1=false;
	String str="4";
	n=scan.nextInt();
	len=str.length();
	while(sum<n)
		{
		sum=0;
		for(i=0;i<len;++i)
			sum+=Integer.parseInt(str.substring(i,i+1));
		if(sum==n)
			{
			flag1=true;
			break;
			}
		flag=true;
		for(i=0;i<len;++i)
			if(!(str.substring(i,i+1).equals("7")))
				{
				flag=false;
				break;
				}
		if(flag)
			{
			str="4";
			for(i=0;i<len;++i)
				str+="4";
			}
		else
			{
			for(i=len-1;i>=0;--i)
				if(str.substring(i,i+1).equals("4"))
					{
					str=str.substring(0,i)+"7"+str.substring(i+1,len);
					break;
					}
			}
		len=str.length();
		}
	if(flag1)
		System.out.println(str);
	else
		System.out.println(-1);
	}
}


import java.util.*;

public class A {

    public static void main(String[] args)  {
        Scanner in = new Scanner(System.in) ;
        int n = in.nextInt() ;
            int a4 = 0;
        int b7 = 0;
        for (int i = n / 7; i >= 0; i--) {
            if ((n - 7 * i) % 4 == 0) {
                b7 = i;
                a4 = (n - 7 * i) / 4;
                StringBuilder builder = new StringBuilder();
                for (int j = 0; i < a4; i++) {
                    builder.append('4');
                }
                for (int j = 0; i < b7; i++) {
                    builder.append('7');
                }
                System.out.println(builder);
            }
        }
        System.out.println(-1);
        in.close();
	}
}


import java.util.*;

public class A {

    public static void main(String[] args)  {
        Scanner in = new Scanner(System.in) ;
        int n = in.nextInt() ;
        int a4 = 0;
        int b7 = 0;
        for (int i = n / 7; i >= 0; i--) {
            if ((n - 7 * i) % 4 == 0) {
                b7 = i;
                a4 = (n - 7 * i) / 4;
                StringBuilder builder = new StringBuilder();
                for (int j = 0; j < a4; j++) {
                    builder.append('4');
                }
                for (int j = 0; j < b7; j++) {
                    builder.append('7');
                }
                System.out.println(builder);
                return;
            }
        }
        System.out.println(-1);
        in.close();
	}
}


import java.util.*;

public class A {

    public static void main(String[] args)  {
        Scanner in = new Scanner(System.in) ;
        int n = in.nextInt() ;
            int a4 = 0;
        int b7 = 0;
        for (int i = n / 7; i >= 0; i--) {
            if ((n - 7 * i) % 4 == 0) {
                b7 = i;
                a4 = (n - 7 * i) / 4;
                StringBuilder builder = new StringBuilder();
                for (int j = 0; i < a4; i++) {
                    builder.append('4');
                }
                for (int j = 0; i < b7; i++) {
                    builder.append('7');
                }
                System.out.println(builder);
                return;
            }
        }
        System.out.println(-1);
        in.close();
	}
}


import java.util.*;

public class A {

    public static void main(String[] args)  {
        Scanner in = new Scanner(System.in) ;
        int n = in.nextInt() ;
        int a4 = 0;
        int b7 = 0;
        for (int i = n / 7; i >= 0; i--) {
            if ((n - 7 * i) % 4 == 0) {
                b7 = i;
                a4 = (n - 7 * i) / 4;
                break;
            }
        }
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < a4; i++) {
            builder.append('4');
        }
        for (int i = 0; i < b7; i++) {
            builder.append('7');
        }
        System.out.println(builder);
        in.close();
	}
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
    public static boolean isLucky(char arr[]){
        for(int i = 0 ; i < arr.length ; i++){
            if(arr[i]!='4' && arr[i]!='7'){
                return false;
            }
        }
        return true;
    }
    public static int getSum(int i){
        int sum = 0;
        while(i > 0){
            sum += i%10;
            i/=10;
        }
        return sum;
    }
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        boolean found = false;
        int n = sc.nextInt();
        for(int i = 1 ; i < 1e6+1 ; i++){
            if(isLucky(String.valueOf(i).toCharArray())){
                //pw.println(i);
                int sum = getSum(i);
                if(sum == n){
                    pw.println(i);
                    found = true;
                    break;
                }
            }
        }
        if(found){

        } else {
            pw.println("-1");
        }

        pw.close();
    }
}


import java.util.*;
import java.io.*;

import static java.lang.Math.*;
public class SomeA {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		boolean found = false;
        int n = sc.nextInt();
        int a = 0;
        int b = 0;
        for(int i = n/7 ; i >= 0; i--){
        	int sum = n - i * 7;
        	if(sum < 0){
        		break;
        	}
        	if(sum % 4 == 0){
        		a = sum / 4;
        		b = i;
        		found = true;
        		break;
        	}
        }
        if(!found){
        	pw.println("-1");
        } else {
        	StringBuilder sb = new StringBuilder("");
        	for(int i = 0 ; i < a ; i++){
        		sb.append('4');
        	}
        	for(int i = 0 ; i < b ; i++){
        		sb.append('7');
        	}
        	pw.println(sb.toString());
        }
		pw.close();
	}

}


import java.util.*;
import java.io.*;

import static java.lang.Math.*;
public class SomeA {
	  public static boolean isLucky(char arr[]){
	        for(int i = 0 ; i < arr.length ; i++){
	            if(arr[i]=='4' || arr[i]=='7'){
	                continue;
	            } else {
	            	return false;
	            }
	        }
	        return true;
	    }
	    public static int getSum(String s){
	        int sum = 0;
	        for(int i = 0 ; i < s.length() ; i++){
	        	sum += (s.charAt(i)-'0');
	        }
	        return sum;
	    }
	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		boolean found = false;
        int n = sc.nextInt();
        String first = "4";
        String second = "7";
        Queue<String> queue = new ArrayDeque<>();
        queue.add(first);
        queue.add(second);
        while(!queue.isEmpty()){
        	String s = queue.poll();
        	int sum = getSum(s);
        	if(sum == n){
        		pw.println(s);
        		found = true;
        		break;
        	}
        	if(sum > n){
        		break;
        	}
        	queue.add(s+"4");
        	queue.add(s+"7");
        }
        if(!found){
        	pw.println("-1");
        }
		pw.close();
	}
	static class Pair implements Comparable<Pair>
	{
		int p,t;
		Pair(int p,int t){
			this.p = p;
			this.t = t;
		}
		public int compareTo(Pair p){
			if(this.p == p.p) return this.t - p.t;
			return p.p - this.p;
		}
	}

}


package competitive_cf;

import java.util.Scanner;

public class _109A {

	public static String generateNumber(int x1, int x2) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < x2; ++i) {
			sb.append('4');
		}

		for (int i = 0; i < x1; ++i) {
			sb.append('7');
		}

		return sb.toString();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = n / 7, x1 = 0, x2 = 0, sumD = -1, x1min = -1, x2min = -1;
		double p;
		for (int i = 0; i <= m; ++i) {
			p = (n - 7 * i) / 4.0;
			x1 = i;
			if (p == (int) p) {
				x2 = (int) p;
//				System.out.println(p + " " + x1 + " " + x2);
				if (sumD == -1) {
					sumD = x1 + x2;
					x1min = x1;
					x2min = x2;
				}

				if (x1 + x2 < sumD) {
					sumD = x1 + x2;
					x1min = x1;
					x2min = x2;
				}

				else if (x1 + x2 == sumD && x2 > x1) {
					sumD = x1 + x2;
					x1min = x1;
					x2min = x2;
				}
//				break;
			}
		}
//		System.out.println("finally " + x1 + " " + x2 + " " + x1min + " " + x2min);

		if (x2min == -1) {
			System.out.println(-1);
		} else {
			System.out.println(generateNumber(x1min, x2min));
//			System.out.println(generateNumber(x1, x2));
		}

	}

}


import java.util.Scanner;

public class _109A {

	public static String generateNumber(int x1, int x2) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < x2; ++i) {
			sb.append('4');
		}

		for (int i = 0; i < x1; ++i) {
			sb.append('7');
		}

		return sb.toString();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = n / 7, x1 = 0, x2 = 0, sumD = -1, x1min = -1, x2min = -1;
		double p;
		for (int i = 0; i <= m; ++i) {
			p = (n - 7 * i) / 4.0;
			x1 = i;
			if (p == (int) p) {
				x2 = (int) p;
//				System.out.println(p + " " + x1 + " " + x2);
				if (sumD == -1) {
					sumD = x1 + x2;
					x1min = x1;
					x2min = x2;
				}

				if (x1 + x2 < sumD) {
					sumD = x1 + x2;
					x1min = x1;
					x2min = x2;
				}

				else if (x1 + x2 == sumD && x2 > x1) {
					sumD = x1 + x2;
					x1min = x1;
					x2min = x2;
				}
//				break;
			}
		}
//		System.out.println("finally " + x1 + " " + x2 + " " + x1min + " " + x2min);

		if (x2min == -1) {
			System.out.println(-1);
		} else {
			System.out.println(generateNumber(x1min, x2min));
//			System.out.println(generateNumber(x1, x2));
		}

	}

}


import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner s = new Scanner(System.in);
      int n = s.nextInt();
      int a = 0;
      int b = 1;
      StringBuilder sb = new StringBuilder();
      while(true)
      {
        int val = n - (7*b);

        if(val >= 0 && val % 4 == 0)
        {
            a = val/4;

            break;
        }

        if(++b*7 > n)
        {
            System.out.println(-1);
            return;
        }

      }

      int a1 = a;
      int add = 0;

      while(a >= 7)
      {
          int x = (a * 4)%7;
          if(x == 0)
          {
              add = (a*4)/7;
              a1 -= a;
              break;
          }

          a--;

      }

       System.out.println("a : " + a1 + " b : " + (b+add));
       for(int i = 0 ; i < a1 ; ++i)
            sb.append(4);
       for(int i = 0 ; i < b+add ; ++i)
            sb.append(7);

        System.out.println(sb.toString());

    }
}


import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner s = new Scanner(System.in);
      int n = s.nextInt();
      int a = 0;
      int b = 1;
      StringBuilder sb = new StringBuilder();
      while(true)
      {
        int val = n - (7*b);

        if(val >= 0 && val % 4 == 0)
        {
            a = val/4;
            for(int i = 0 ; i < a ; ++i)
                sb.append(4);
            for(int i = 0 ; i < b ; ++i)
                sb.append(7);

            System.out.println(sb.toString());
            return;
        }

        if(++b*7 > n)
        {
          break;
        }

      }

      System.out.println(-1);

    }
}


import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner s = new Scanner(System.in);
      int n = s.nextInt();
      int a = 0;
      int b = 1;
      StringBuilder sb = new StringBuilder();
      while(true)
      {
        int val = n - (7*b);

        if(val >= 0 && val % 4 == 0)
        {
            a = val/4;

            break;
        }

        if(++b*7 > n)
        {
            System.out.println(-1);
            return;
        }

      }

      int a1 = a;
      int add = 0;

      while(a >= 7)
      {
          int x = (a * 4)%7;
          if(x == 0)
          {
              add = (a*4)/7;
              a1 -= a;
              break;
          }

          a--;

      }

       for(int i = 0 ; i < a1 ; ++i)
            sb.append(4);
       for(int i = 0 ; i < b+add ; ++i)
            sb.append(7);

        System.out.println(sb.toString());

    }
}


import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner s = new Scanner(System.in);
      int n = s.nextInt();
      int a = 0;
      int b = 0;
      StringBuilder sb = new StringBuilder();
      while(true)
      {
        int val = n - (7*b);

        if(val >= 0 && val % 4 == 0)
        {
            a = val/4;

            break;
        }

        if(++b*7 > n)
        {
            System.out.println(-1);
            return;
        }

      }

      int a1 = a;
      int add = 0;

      while(a >= 7)
      {
          int x = (a * 4)%7;
          if(x == 0)
          {
              add = (a*4)/7;
              a1 -= a;
              break;
          }

          a--;

      }

       for(int i = 0 ; i < a1 ; ++i)
            sb.append(4);
       for(int i = 0 ; i < b+add ; ++i)
            sb.append(7);

        System.out.println(sb.toString());

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Lucky_Sum_of_Digits_CF {
	static boolean f = false;
	static String st = "";

	static int sumDigits(String x) {
		int s = 0;
		for (int i = 0; i < x.length(); i++) {
			s += Integer.parseInt(x.charAt(i) + "");
		}
		return s;
	}

	static void lucky(String s, int x) {
		if (sumDigits(s) == x) {
			f = true;
			if (st==""||Long.parseLong(s) < Long.parseLong(st))
				st = s;

			return;

		} else if (sumDigits(s) > x)
			return;
		else {
			lucky(s + "4", x);
			lucky(s + "7", x);
		}

	}

	public static void main(String[] args) throws Exception {
		InputStreamReader in = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(in);
		String[] x = br.readLine().split(" ");
		int n = Integer.parseInt(x[0]);
		lucky("4", n);
		if (f) {
			System.out.println(st);
		} else
			System.out.println(-1);

	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Lucky_Sum_of_Digits_CF {
	static boolean f = false;
	static String st = "";

	static int sumDigits(String x) {
		int s = 0;
		for (int i = 0; i < x.length(); i++) {
			s += Integer.parseInt(x.charAt(i) + "");
		}
		return s;
	}

	static void lucky(String s, int x) {
		if (s!=""&&sumDigits(s) == x) {
			f = true;
			if (st==""||Long.parseLong(s) < Long.parseLong(st))
				st = s;

			return;

		} else if (s!=""&&sumDigits(s) > x)
			return;
		else {
			lucky(s + "4", x);
			lucky(s + "7", x);
		}

	}

	public static void main(String[] args) throws Exception {
		InputStreamReader in = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(in);
		String[] x = br.readLine().split(" ");
		int n = Integer.parseInt(x[0]);
		lucky("", n);
		if (f) {
			System.out.println(st);
		} else
			System.out.println(-1);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class CF_109_A_LUCKY_SUM_OF_DIGITS {

	static ArrayList<Long> lucky;

	static void generate(String s , int length)
	{

		if(s.length() == length )
		{

			lucky.add(Long.parseLong(s));
			return ;

		}

		generate(s+"4", length);
		generate(s+"7", length);

	}

	static int calcSum(long x)
	{
		long temp = x ;
		int ans = 0;
		while(temp>0)
		{
			ans+= temp%10;
			temp/=10;

		}

		return ans ;
	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		lucky = new ArrayList<>();
		for(int i = 1  ; i <= 12 ; i++)
			generate("", i);

		Collections.sort(lucky);

		long n = sc.nextLong();
		for(int i = 0 ; i<lucky.size() ;i++)
		{
			if(calcSum(lucky.get(i)) == n )
			{
				System.out.println(lucky.get(i));
				return ;
			}

		}

		System.out.println(-1);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class CF_109_A_LUCKY_SUM_OF_DIGITS {

	static ArrayList<Long> lucky;

	static void generate(String s , int length)
	{

		if(s.length() == length )
		{

			lucky.add(Long.parseLong(s));
			return ;

		}

		generate(s+"4", length);
		generate(s+"7", length);

	}

	static int calcSum(long x)
	{
		long temp = x ;
		int ans = 0;
		while(temp>0)
		{
			ans+= temp%10;
			temp/=10;

		}

		return ans ;
	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		lucky = new ArrayList<>();
		for(int i = 1  ; i <= 12 ; i++)
			generate("", i);

		Collections.sort(lucky);

		long n = sc.nextLong();
		String s = "";
		long ans = 0;
		long calc = n;

		while(calc>0)
		{

			if(calc % 7 == 0) {
				s+="7";
				calc-=7;
				ans+=7;
			}else  {
				s+="4";
				calc-=4;
				ans+=4;
			}

		}

		System.out.println(calc == 0 ? s : -1);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class CF_109_A_LUCKY_SUM_OF_DIGITS {

	static ArrayList<Long> lucky;

	static void generate(String s , int length)
	{

		if(s.length() == length )
		{

			lucky.add(Long.parseLong(s));
			return ;

		}

		generate(s+"4", length);
		generate(s+"7", length);

	}

	static int calcSum(long x)
	{
		long temp = x ;
		int ans = 0;
		while(temp>0)
		{
			ans+= temp%10;
			temp/=10;

		}

		return ans ;
	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		lucky = new ArrayList<>();
		for(int i = 1  ; i <= 8 ; i++)
			generate("", i);

		Collections.sort(lucky);

		long n = sc.nextLong();
		for(int i = 0 ; i<lucky.size() ;i++)
		{
			if(calcSum(lucky.get(i)) == n )
			{
				System.out.println(lucky.get(i));
				return ;
			}

		}

		System.out.println(-1);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class CF_109_A_LUCKY_SUM_OF_DIGITS {

	static ArrayList<Long> lucky;

	static void generate(String s , int length)
	{

		if(s.length() == length )
		{

			lucky.add(Long.parseLong(s));
			return ;

		}

		generate(s+"4", length);
		generate(s+"7", length);

	}

	static int calcSum(long x)
	{
		long temp = x ;
		int ans = 0;
		while(temp>0)
		{
			ans+= temp%10;
			temp/=10;

		}

		return ans ;
	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		lucky = new ArraList<>();
		for(int i = 1  ; i <= 8 ; i++)
			generate("", i);

		Collections.sort(lucky);

		long n = sc.nextLong();
		for(int i = 0 ; i<lucky.size() ;i++)
		{
			if(calcSum(lucky.get(i)) == n )
			{
				System.out.println(lucky.get(i));
				return ;
			}

		}

		System.out.println(-1);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}


#include <bits/stdc++.h>
using namespace std;
static vector<int> a;
static vector<int> b;
int main(){
    int n;
    scanf("%d", &n);
    if(n%2 == 0){
        cout << -1 << endl;
        return 0;
    }
    for(int i = 0; i<n; i++){
        cout<<i<< " ";
        a.emplace_back(i);
    }
    cout<<endl;
    cout<<n-2 << " ";
    cout<< n-1 << " ";
    b.emplace_back(n-2);
    b.emplace_back(n-1);
    for(int i = 0; i<n-2; i++){
        cout<< i<< " ";
        b.emplace_back(i);
    }
    cout<< endl;
    for(int i = 0; i<n; i++){
        cout<< (a[i] + b[i])%n << " ";
    }

    return 0;
}


#include"bits/stdc++.h"
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	if(n%2==0)
	{
		printf("-1");
		return 0;
	}
	for(register int i=0;i<=n-1;i++)
	printf("%d ",i);
	cout<<endl;
	for(register int i=0;i<=n-2;i++)
	printf("%d ",i+1);
	cout<<0<<endl;
	for(register int i=0;i<=n-1;i++)
	printf("%d ",(2*i+1)%n);
	return 0;
}


#include <iostream>
using namespace std;

#define a(h) for(x=0;x<n;x++)cout<<h<<' ';cout<<endl;

int n,x;

main()
{
    cin>>n;

    if(n%2)
    {
        a(x)
        a(x)
        a((x*2)%n)
    }

    else    cout<<-1;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	if(n%2==1){
		for(int i=0;i<n;i++)printf("%d ",i);
		printf("\n");
		for(int i=1;i<n;i++)printf("%d ",i);
		printf("0");
		printf("\n");
		for(int i=1;i<=n;i++)
			printf("%d ",(i-1+i%n)%n);
		printf("\n");
	}
	else printf("-1\n");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	if(n&1)
	{
		for(int i=0;i<n;i++)printf("%d ",i);putchar('\n');
		for(int i=0;i<n;i++)printf("%d ",i);putchar('\n');
		for(int i=0;i<n;i++)printf("%d ",2*i%n);putchar('\n');
	}
	else puts("-1");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	if(n&1)
	{
		for(int i=0;i<n;i++)cout<<i<<' ';putchar('\n');
		for(int i=0;i<n;i++)cout<<i<<' ';putchar('\n');
		for(int i=0;i<n;i++)cout<<2*i%n<<' ';putchar('\n');
	}
	else puts("-1");
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int f1[n];
  int f3[n];
  if(n%2 == 0){
      cout << -1;
      return 0;
      }

  for(int i = 0; i < n; i++){
      f1[i] = i;
      f3[i] = (f1[i]*2)%n;
    }

    for(int i = 0; i < n; i++){
        cout << f1[i] << " ";
    }
    cout<< "\n";
     for(int i = 0; i < n; i++){
        cout << f1[i] << " ";
     }
     cout<< "\n";
     for(int i = 0; i < n; i++){
        cout << f3[i] << " ";
     }

     return 0;
}


#include <bits/stdc++.h>

#define llong long long

using namespace std;

typedef vector<int> big;

const int MAXN = (int) 2e6 + 7;
const int INF = (int) 1e9 + 7;

int n;
int a[MAXN];

int main() {
  #ifdef LOCAL
  freopen("in", "r", stdin);
  #endif

  scanf("%d", &n);
  if (n == 1) printf("0\n0\n0");
  if (n & 1) {
    for (int i = 0; i < n; i++) {
      printf("%d ", (i + i) % n);
    }
    printf("\n");
    for (int i = 0; i < n; i++) {
      printf("%d ", (n - i) % n);
    }
    printf("\n");
    for (int i = 0; i < n; i++) {
      printf("%d ", (n + i) % n);
    }
  }
  else {
    puts("-1");
  }

  return 0;
}


#include <bits/stdc++.h>

#define llong long long

using namespace std;

typedef vector<int> big;

const int MAXN = (int) 2e6 + 7;
const int INF = (int) 1e9 + 7;

int n;
int a[MAXN];

int main() {
  #ifdef LOCAL
  freopen("in", "r", stdin);
  #endif

  scanf("%d", &n);
  if (n & 1) {
    for (int i = 0; i < n; i++) {
      printf("%d ", (i + i) % n);
    }
    printf("\n");
    for (int i = 0; i < n; i++) {
      printf("%d ", (n - i) % n);
    }
    printf("\n");
    for (int i = 0; i < n; i++) {
      printf("%d ", (n + i) % n);
    }
  }
  else {
    puts("-1");
  }

  return 0;
}


#include<bits/stdc++.h>
#define reg register
#define ll long long
using namespace std;
ll n;
int main()
{
    scanf("%lld",&n);
    if(!(n&1))return puts("-1"),0;
    for(reg ll i=0;i<=n-1;i++)printf("%lld ",i);
    cout<<endl;
    for(reg ll i=0;i<=n-1;i++)printf("%lld ",i);
    cout<<endl;
    for(reg ll i=0;i<=n-1;i++)printf("%lld ",((i%n)<<1)%n);
    return 0;
}


#include <cstdio>

int main() {
  long n;
  scanf("%ld\n", &n);

  if (n % 2) {
    for (long p = 0; p < n; p++) {
      printf("%ld ", p);
    };
    puts("");
    for (long p = 0; p < n; p++) {
      printf("%ld ", p);
    };
    puts("");
    for (long p = 0; p < n; p++) {
      printf("%ld ", (2 * p) % n);
    };
    puts("");
  } else {
    puts("-1");
  }

  return 0;
}


#include <cstdio>

int main(){

    long n; scanf("%ld\n", &n);

    if(n % 2){
        for(long p = 0; p < n; p++){printf("%ld ", p);}; puts("");
        for(long p = 0; p < n; p++){printf("%ld ", p);}; puts("");
        for(long p = 0; p < n; p++){printf("%ld ", (2 * p) % n);}; puts("");
    }
    else{puts("-1");}

    return 0;
}


//lxrtxdy!
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	if(n%2==0)cout<<"-1";
	else
	{
		for(int i=0;i<n;i++)cout<<i<<" ";
		cout<<"\n";
		for(int i=1;i<=n;i++)cout<<i%n<<" ";
		cout<<"\n";
		for(int i=0;i<n;i++)cout<<(i+i+1)%n<<" ";
		cout<<"\n";
	}
	return 0;
}
//orzlxr!//hello


/*************************************************************************
    > File Name: a.cpp
    > Author: liangxianfeng
    > Mail:   liangxianfeng96@qq.com
    > Created Time: 2016年10月31日 星期一 18时59分18秒
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <ctime>

using namespace std;
#define ll long long
#define rep(i,n) for(int i =0; i < n; ++i)
#define repp(i,n,x) for(int i =x; i < n+x; ++i)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(a,b) memset(a,b,sizeof a)
#define pr(x) cout << #x << " = " << x << " ";
#define prln(x) cout << #x << " = " << x <<  endl;
const int maxn = 4e5+100;
const int INF = 0x3f3f3f3f;

int n;
int a[maxn];
int main(){
#ifdef LOCAL
	freopen("/home/zeroxf/桌面/in.txt","r",stdin);
	//freopen("/home/zeroxf/桌面/out.txt","w",stdout);
#endif
    int n;
    while(cin >> n){
        if(n&1){
            rep(i,n) printf("%d ",i);
            printf("\n");

            rep(i,n) printf("%d ",n-i-1);
            printf("\n");

            for(int i = 1; i < n; i += 2) printf("%d ",i);
            for(int i = 0; i < n; i += 2) printf("%d ",i);
            printf("\n");

        }else printf("-1\n");
    }

	return 0;
}


/*************************************************************************
    > File Name: a.cpp
    > Author: liangxianfeng
    > Mail:   liangxianfeng96@qq.com
    > Created Time: 2016年10月31日 星期一 18时59分18秒
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <ctime>

using namespace std;
#define ll long long
#define rep(i,n) for(int i =0; i < n; ++i)
#define repp(i,n,x) for(int i =x; i < n+x; ++i)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(a,b) memset(a,b,sizeof a)
#define pr(x) cout << #x << " = " << x << " ";
#define prln(x) cout << #x << " = " << x <<  endl;
const int maxn = 4e5+100;
const int INF = 0x3f3f3f3f;

int n;
int a[maxn];
int main(){
#ifdef LOCAL
	freopen("/home/zeroxf/桌面/in.txt","r",stdin);
	//freopen("/home/zeroxf/桌面/out.txt","w",stdout);
#endif
    int n;
    while(cin >> n){
        if(n&1){

            rep(i,n) printf("%d ",n-i-1);
            printf("\n");

            for(int i = 1; i < n; i += 2) printf("%d ",i);
            for(int i = 0; i < n; i += 2) printf("%d ",i);
            printf("\n");

            rep(i,n) printf("%d ",i);
            printf("\n");

        }else printf("-1\n");
    }

	return 0;
}


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

int main(){
    int n;
    cin>>n;
    if(n%2==0){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
        cout<<i<<' ';
    cout<<endl;
    for(int i=0;i<n;i++)
        cout<<i<<' ';
    cout<<endl;
    for(int i=0;i<n;i++)
        cout<<(i*2)%n<<' ';

    cout<<endl;
    return 0;
}//hello


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ipair pair<int,int>
main()
{
    int n;
    cin>>n;
   int a[n],b[n];
   for(int i=0;i<n;i++)
    a[i]=i;
   int p=1;
   for(int i=0;i<n;i++)
   {
       b[i]=p;
       p++;
       p%=n;
   }
   if(n%2==0) cout<<-1;
   else if(n==1)
   {
       cout<<0<<endl<<0<<endl<<0;
   }
   else
   {
       for(int i=0;i<n;i++) cout<<a[i]<<' ';
       cout<<endl;
       for(int i=0;i<n;i++) cout<<b[i]<<' ';
       cout<<endl;
       for(int i=0;i<n;i++) cout<<(a[i]+b[i])%n<<' ';
       cout<<endl;
   }
   return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

int a[100100];
int b[100100];
int c[100100];

int main(){
    int n;
    cin>>n;
    int k =0 ;
    for(int i=0 ;i <n ;i ++){
        a[i] = i;
    }
    int j = 1;
    j %= n;
    for(int i=0 ;i <n ;i ++){
        b[i] = j;
        j++;
        j %= n;
    }
    for(int i=0 ;i <n ;i ++){
        c[i] = a[i]+b[i];
        c[i] %= n;
    }

    set<int>st;
    for(int i=0 ;i <n ;i ++){
        st.insert(c[i]);
    }
    if(st.size()!=n){
        cout<<-1;
        return 0;
    }
    for(int i=0 ;i <n ;i ++){
        printf("%d ",a[i]);
    }
    printf("\n");
    for(int i=0 ;i <n ;i ++){
        printf("%d ",b[i]);
    }
    printf("\n");
    for(int i=0 ;i <n ;i ++){
        printf("%d ",c[i]);
    }
    printf("\n");

    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

int a[100100];
int b[100100];
int c[100100];

int main(){
    int n;
    cin>>n;
    int k =0 ;
    for(int i=0 ;i <n ;i ++){
        a[i] = i;
    }
    int j = 1;
    for(int i=0 ;i <n ;i ++){
        b[i] = j;
        j++;
        j %= n;
    }
    for(int i=0 ;i <n ;i ++){
        c[i] = a[i]+b[i];
        c[i] %= n;
    }

    set<int>st;
    for(int i=0 ;i <n ;i ++){
        st.insert(c[i]);
    }
    if(st.size()!=n){
        cout<<-1;
        return 0;
    }
    for(int i=0 ;i <n ;i ++){
        printf("%d ",a[i]);
    }
    printf("\n");
    for(int i=0 ;i <n ;i ++){
        printf("%d ",b[i]);
    }
    printf("\n");
    for(int i=0 ;i <n ;i ++){
        printf("%d ",c[i]);
    }
    printf("\n");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>

#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>

using namespace std;

const int N = (int)1e5 + 7;
int n, m, sum, x, y, a[N], b[N], c[N];
ll  ans;
vector<int> v1, v2;
set<int> st, st1, st2;

int main()
{
	cin >> n;
	x = (n - 1) * n / 2;
	if(x % 10)
	{
		cout << -1;
		return 0;
	}
	for(int i = 0; i < n; i++)
		cout << i << ' ';
	cout << endl;
	for(int i = 1; i < n; i++)
		cout << i << ' ';
	cout << 0 << endl;
	for(int i = 0; i < n - 1; i++)
		cout << (i + i + 1) % n << ' ';
	cout << n - 1 << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>

#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>

using namespace std;

const int N = (int)1e5 + 7;
ll n, m, sum, x, y;//a[N], b[N], c[N];
ll  ans;
vector<int> v1, v2;
set<int> st, st1, st2;

int main()
{
	cin >> n;
	x = (n - 1LL) * n / 2LL;
	if(x % n)
	{
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < n; i++)
		cout << i << ' ';
	cout << endl;
	for(int i = 1; i < n; i++)
		cout << i << ' ';
	cout << 0 << endl;
	for(int i = 0; i < n - 1; i++)
		cout << (i + i + 1) % n << ' ';
	cout << n - 1 << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>

#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>

using namespace std;

const int N = (int)1e5 + 7;
int n, m, sum, x, y, a[N], b[N], c[N];
ll  ans;
vector<int> v1, v2;
set<int> st, st1, st2;

int main()
{
	cin >> n;
	x = (n - 1) * n / 2;
	if(x % n)
	{
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < n; i++)
		cout << i << ' ';
	cout << endl;
	for(int i = 1; i < n; i++)
		cout << i << ' ';
	cout << 0 << endl;
	for(int i = 0; i < n - 1; i++)
		cout << (i + i + 1) % n << ' ';
	cout << n - 1 << endl;

	return 0;
}


#include<cstdio>
using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	if(n%2==0){
		printf("-1\n");
	}
	else{
		int arr1[n],arr2[n],arr3[n];
		for(int i=0;i<n;i++)arr1[i] = i;
		int counter = n-2;
		for(int i=0;i<n/2;i++){
			arr2[i] = counter;
			counter-=2;
		}
		counter = n-1;
		for(int i=n/2;i<n;i++){
			arr2[i] = counter;
			counter-=2;
		}
		for(int i=0;i<n;i++){
			arr3[i] = (arr1[i]+arr2[i])%n;
		}
		for(int i=0;i<n;i++)printf("%d ",arr1[i]);
		printf("\n");
		for(int i=0;i<n;i++)printf("%d ",arr2[i]);
		printf("\n");
		for(int i=0;i<n;i++)printf("%d ",arr3[i]);
		printf("\n");
	}
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 1e5+10;

int n;
int a[MAXN], b[MAXN], c[MAXN];
int cnt[MAXN];
bool haveb[MAXN],havec[MAXN];

void pr() {
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	cout << endl;
	for(int i = 0; i < n; i++) cout << b[i] << " ";
	cout << endl;
	for(int i = 0; i < n; i++) cout << c[i] << " ";
	cout << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	memset(haveb,0,sizeof(haveb));
	memset(havec,0,sizeof(havec));
	if(n % 2 == 0) {
		cout << -1 << endl;
		return 0;
	}
	if(n % 3 == 0) {
		for(int i = 0; i < n; i++)
			a[i] = b[i] = i;
		for(int i = 0; i < n; i++)
			c[i] = (a[i]+b[i]) %n;
		pr();
		return 0;
	/*	cout << endl;

	/*for(int i = 0; i < n; i++) {
		cnt[c[i]]++;
	}
	for(int i = 0; i < n; i++) {
		if(cnt[i] < 1) cout << " wu :" << i << endl;
		else if(cnt[i] > 1) cout << " chong :" << i << endl;
	}
	*/

	}
	for(int i = 0; i < n; i++)
		a[i] = i;
	int last = 0;
	for(int i = 1; i < n; i+=2) {
		while(haveb[(last)%n] || havec[(i+last)%n]) last++;
		b[i] = (last++)%n;
		haveb[b[i]] = 1;
		c[i] = (a[i]+b[i])%n;
		havec[c[i]] = 1;
	}
	for(int i = 0; i < n; i+=2) {
		while(haveb[(last)%n] || havec[(i+last)%n]) last++;
		b[i] = (last++)%n;
		haveb[b[i]] = 1;
		c[i] = (a[i]+b[i])%n;
		havec[c[i]] = 1;
	}
	pr();
	/*for(int i = 0; i < n; i++) {
		cnt[c[i]]++;
	}

	cout << endl;
	for(int i = 0; i < n; i++) {
		if(cnt[i] < 1) cout << " wu :" << i << endl;
		else if(cnt[i] > 1) cout << " chong :" << i << endl;
	}*/
	return 0;
}


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

typedef long long ll;
typedef long double ld;

const int N=1e5+10;

int main(){
    //freopen("a.txt", "r", stdin);
    //freopen("answers.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    if(n%2==0){
        cout<<-1<<endl;
        return 0;
    }
    if(n==1){
        for(int i=0;i<3;i++){
            cout<<0<<endl;
        }
        return 0;
    }
    int a[n];
    for(int i=0;i<n;i++){
        cout<<i<<" ";
        a[i]=i;
    }
    cout<<endl;
    for(int i=0;i<n;i++){
        cout<<(i+1)%n<<" ";
        a[i]+=(i+1)%n;
        a[i]%=n;
    }
    cout<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;

    return 0;

}


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

typedef long long ll;
typedef long double ld;

const int N=1e5+10;

int main(){
    //freopen("a.txt", "r", stdin);
    //freopen("answers.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    if(n%2==0 || n==1){
        cout<<-1<<endl;
        return 0;
    }
    int a[n];
    for(int i=0;i<n;i++){
        cout<<i<<" ";
        a[i]=i;
    }
    cout<<endl;
    for(int i=0;i<n;i++){
        cout<<(i+1)%n<<" ";
        a[i]+=(i+1)%n;
        a[i]%=n;
    }
    cout<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;

    return 0;

}


/**
  *                              ------------------------- ALLAH is Almighty -----------------------------
  *  @author: OBAJN VEEO
  *  University: TSUS
  *  OJ: CF
  *  problem name: A. Lucky Permutation Triple
  * Category :
  */

// Pre_code

#include <bits/stdc++.h>

// header file

#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <numeric>
#include <cstring>

using namespace std ;

//define function

#pragma comment(linker, "/STACK:667772160")
#define forln(i,a,n) for(int i=a ; i<n ; i++)
#define foren(i,a,n) for(int i=a ; i<=n ; i++)
#define forg0(i,a,n) for(int i=a ; i>n ; i--)
#define fore0(i,a,n) for(int i=a ; i>=n ; i--)
#define pb push_back
#define pp pop_back
#define clr(a,b) memset(a,b,sizeof(a))
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf1ll(a) scanf("%lld",&a)
#define sf2ll(a,b) scanf("%lld %lld",&a,&b)
#define pii acos(-1.0)
#define jora_int pair<int,int>
#define jora_ll pair<long long,long long>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define Max 15000000+9
#define sz 100000+7
#define Mod 100000000
#define EPS 1e-10
#define ll long long
#define ull unsigned long long
#define fs first
#define sc second
#define wait system("pause")
#define sf scanf
#define pf printf
#define mp make_pair
#define ps pf("PASS\n")

//debug

template<class T1> void deb(T1 e1)
{
    cout<<e1<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2)
{
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3)
{
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}

// moves

//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*night move*/

//close

int arr[100010] ;

int main()
{
    int n ;

    sf1(n);

    if(!(n&1))
        deb(-1);

    else
    {
        for(int i=0 ; i<n ; i++)
        {
            arr[i] = (2*i)%n ;

            if(i)
                pf(" ");
            pf("%d",i);
        }
        pf("\n");
        for(int i=0 ; i<n ; i++)
        {
            if(i)
                pf(" ");
            pf("%d",i);
        }
        pf("\n");

        for(int i=0 ; i<n ; i++)
        {
            if(i)
                pf(" ");
            pf("%d",arr[i]);
        }
        pf("\n");
    }

    return 0;
}


/**
  *                              ------------------------- ALLAH is Almighty -----------------------------
  *  @author: M. NAZIM UDDIN
  *  University: SUST
  *  OJ: CF
  *  problem name:
  * Category :
  */

// Pre_code

#include <bits/stdc++.h>

// header file

#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <numeric>
#include <cstring>

using namespace std ;

//define function

#pragma comment(linker, "/STACK:65536000")
#define forln(i,a,n) for(int i=a ; i<n ; i++)
#define foren(i,a,n) for(int i=a ; i<=n ; i++)
#define forg0(i,a,n) for(int i=a ; i>n ; i--)
#define fore0(i,a,n) for(int i=a ; i>=n ; i--)
#define pb push_back
#define pp pop_back
#define clr(a,b) memset(a,b,sizeof(a))
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf1ll(a) scanf("%lld",&a)
#define sf2ll(a,b) scanf("%lld %lld",&a,&b)
#define pii acos(-1.0)
#define jora_int pair<int,int>
#define jora_ll pair<long long,long long>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define Max 10000000000000
#define sz 100000+7
#define Mod 1000000009
#define EPS 1e-10
#define ll long long
#define ull unsigned long long
#define fs first
#define sc second
#define wait system("pause")
#define sf scanf
#define pf printf
#define mp make_pair
#define ps pf("PASS\n")
#define read freopen("input.txt","r",stdin)

//debug

template<class T1> void deb(T1 e1)
{
    cout<<e1<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2)
{
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3)
{
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}

// moves

//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
int dx[]= {0,1,-1};/*4 side move*/
int dy[]= {1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*night move*/

//close

char graph[110][4][110] , n , x , y , ck ;

bool bfs()
{
    queue< pair<int,jora_int> >q ;
    q.push(mp(0,mp(x,y)));

    while(!q.empty())
    {
        jora_int u = q.front().sc ;
        int tm = q.front().fs ;

        if(tm == n)
            ck = 1 ;

        if(tm<n)
        {
            if(graph[tm+1][u.fs][u.sc] == '.')
                q.push(mp(tm+1,mp(u.fs,u.sc)));

            if(u.fs>0 and graph[tm+1][u.fs-1][u.sc] == '.')
                q.push(mp(tm+1,mp(u.fs-1,u.sc)));

            if(u.fs<2 and graph[tm+1][u.fs+1][u.sc] == '.')
                q.push(mp(tm+1,mp(u.fs+1,u.sc)));
        }
    }

    return ck ;
}

int main()
{
    int t , tr;

    sf1(t);

    while(t--)
    {
        sf2(n,tr);

        sf("%s %s %s",graph[0][0],graph[0][1],graph[0][2]);

        if(graph[0][0][0] == 's')
        {
            if(graph[0][0][1] != '.')
            {
                pf("NO\n");
                return 0;
            }
            x = 0 ;
            y = 0 ;
        }

        else if(graph[0][1][0] == 's')
        {
            if(graph[0][1][1] != '.')
            {
                pf("NO\n");
                return 0;
            }
            x = 1 ;
            y = 0 ;
        }

        else if(graph[0][2][0] == 's')
        {
            if(graph[0][2][1] != '.')
            {
                pf("NO\n");
                return 0;
            }
            x = 2 ;
            y = 0 ;
        }

        for(int i=1 ; i<=n ; i++)
        {
            for(int j=0 ; j<n-2 ; j++)
            {
                graph[i][0][j] = graph[i-1][0][j+2] ;
                graph[i][1][j] = graph[i-1][1][j+2] ;
                graph[i][2][j] = graph[i-1][2][j+2] ;
            }
            graph[i][0][n-2] = '.' ;
            graph[i][1][n-2] = '.' ;
            graph[i][2][n-2] = '.' ;
            graph[i][0][n-1] = '.' ;
            graph[i][1][n-1] = '.' ;
            graph[i][2][n-1] = '.' ;
        }

        if(ck)
            printf("YES\n");
        else
            pf("NO\n");

    }
    return 0;
}


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

int main() {
	ios::sync_with_stdio(false);

	int n; cin >> n;
	if (n%2 == 0) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		cout << i << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		cout << i << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		cout << (i*2 % n) << " ";
	}
	cout << endl;

	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);

	int n; cin >> n;
	if (n == 1) {
		cout << "0\n0\n0" << endl;
		return 0;
	}
	if (n == 2) {
		cout << -1 << endl;
		return 0;
	}
	for (int k = 2; k*k <= n; k++) {
		if (n%k == 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i+1 << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		cout << i+1 << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		cout << ((i+1)*2 % n) << " ";
	}
	cout << endl;

	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);

	int n; cin >> n;
	if (n == 1) {
		cout << "0\n0\n0" << endl;
		return 0;
	}
	if (n == 2) {
		cout << -1 << endl;
		return 0;
	}
	for (int k = 2; k*k <= n; k++) {
		if (n%k == 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		cout << i << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		cout << (i*2 % n) << " ";
	}
	cout << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

	int n;
	cin>>n;
	if(n%2 == 0) cout<<-1<<endl;
	else
		for(int i = 0;i<n;i++){
			cout<<i<<" ";
		}
		cout<<endl;
		for(int j = 0; j<n; j++){
			cout<<j<<" ";
		}
		cout<<endl;
		for(int m=0; m<n; m++){
			cout<<(m+m) % n<<" ";
		}
		cout<<endl;
	return 0;
}


#include <cstdio>

using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	if(n % 2 == 0){
		printf("-1\n");
	}
	else{
		for(int a = 0; a < n; a++)
			printf("%d ", a);
		printf("\n");
		for(int b = 0; b < n; b++)
			printf("%d ", b);
		printf("\n");
		for(int a = 0; a < n; a++)
			printf("%d ", (a + a) % n);
		printf("\n");
	}
}


//Author:Barry Wang
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int main()
{
	cin>>n;
	if(n%2==0)
	{
		cout<<"-1\n";
		exit(0);
	}
	for(int i=0;i<n;++i)
	{
		cout<<i<<' ';
	}
	cout<<'\n';
	for(int i=0;i<n;++i)
	{
		cout<<i<<' ';
	}
	cout<<'\n';
	for(int i=0;i<n;++i)
	{
		int out=i+i;
		if(out>=n)
		{
			out-=n;
		}
		cout<<out<<' ';
	}
	cout<<'\n';
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int n;

int main()
{
	scanf("%d",&n);
	if (~n & 1)
	{
		puts("-1");
		return 0;
	}
	for (int i = 0;i < n;i++)
		printf("%d ",i);
	printf("\n");
	for (int i = 0;i < n;i++)
		printf("%d ",i);
	printf("\n");
	for (int i = 0;i < n;i++)
		printf("%d ",2 * i % n);
	printf("\n");
	return 0;
}