#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

template <typename K, typename V = __gnu_pbds::null_type>
using tree = __gnu_pbds::tree<K, V, less<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
using llong = long long;
auto isz = [](const auto& c) { return int(c.size()); };
mt19937 rng((size_t) make_shared<char>().get());

#ifndef _LIB_FASTIO_
#define _LIB_FASTIO_

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
#pragma GCC diagnostic ignored "-Wconversion"

/** Fast allocation */

#ifdef FAST_ALLOCATOR_MEMORY
	int allocator_pos = 0;
	char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
	inline void * operator new ( size_t n ) {
		char *res = allocator_memory + allocator_pos;
		allocator_pos += n;
		assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
		return (void *)res;
	}
	inline void operator delete ( void * ) noexcept { }
	//inline void * operator new [] ( size_t ) { assert(0); }
	//inline void operator delete [] ( void * ) { assert(0); }
#endif

/** Fast input-output */

/** Read */

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
	if (buf_pos == buf_len) {
		buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
		if (buf_pos == buf_len)
			return 1;
	}
	return 0;
}

inline int getChar() {
	return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
	return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
	int c;
	while ((c = peekChar()) != -1 && c <= 32)
		buf_pos++;
	return c == -1;
}

inline void skipBlanks() {
	while (!isEof() && buf[buf_pos] <= 32U)
		buf_pos++;
}

inline int readChar() {
	int c = getChar();
	while (c != -1 && c <= 32)
		c = getChar();
	return c;
}

inline unsigned int readUInt() {
	int c = readChar();
	unsigned int x = 0;
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return x;
}

template <class T = int>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	else if (c == '+')
		c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

inline long long readLong() {
	return readInt<long long>();
}

inline double readDouble() {
	int s = 1, c = readChar();
	double x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	if (c == '.') {
		c = getChar();
		double coef = 1;
		while ('0' <= c && c <= '9')
			x += (c - '0') * (coef *= 1e-1), c = getChar();
	}
	return s == 1 ? x : -x;
}

inline void readWord( char *s ) {
	int c = readChar();
	while (c > 32)
		*s++ = c, c = getChar();
	*s = 0;
}

inline void readWord( string &s ) {
	s.clear();
	int c = readChar();
	while (c > 32)
		s += c, c = getChar();
}

inline bool readLine( char *s ) {
	int c = getChar();
	while (c != '\n' && c != -1)
		*s++ = c, c = getChar();
	*s = 0;
	return c != -1;
}

inline bool readLine( string &s ) {
	s.clear();
	int c = getChar();
	while (c != '\n' && c != -1)
		s += c, c = getChar();
	return c != -1;
}

/** Write */

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_buf_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
	write_buf[write_buf_pos++] = x;
}

inline void flush() {
	if (write_buf_pos) {
		fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
		fflush(stdout);
	}
}

template <class T>
inline void writeInt( T x, char end = 0, int output_len = -1) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n < output_len)
		s[n++] = '0';
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

inline void writeWord(const string& s) {
	writeWord(s.c_str());
}

inline void writeDouble( double x, int output_len = 0) {
	if (x < 0)
		writeChar('-'), x = -x;
	int t = (int)x;
	writeInt(t), x -= t;
	writeChar('.');
	for (int i = output_len - 1; i > 0; i--) {
		x *= 10;
		t = std::min(9, (int)x);
		writeChar('0' + t), x -= t;
	}
	x *= 10;
	t = std::min(9, (int)(x + 0.5));
	writeChar('0' + t);
}

/** Buffer flusher */

static struct buffer_flusher_t {
	~buffer_flusher_t() {
		flush();
	}
} buffer_flusher;

/** Reader and writer */

struct fast_reader {
    fast_reader& operator>>(int& n) {
        n = readInt(); return *this;
    }
    fast_reader& operator>>(unsigned int& n) {
        n = readUInt(); return *this;
    }
    fast_reader& operator>>(llong& n) {
        n = readLong(); return *this;
    }
	fast_reader& operator>>(double& n) {
        n = readDouble(); return *this;
    }
	fast_reader& operator>>(float& n) {
        n = (float) readDouble(); return *this;
    }
    fast_reader& operator>>(string& s) {
        readWord(s); return *this;
    }
    fast_reader& operator>>(char& c) {
        c = (char) readChar(); return *this;
    }
    template<typename T>
    fast_reader& operator>>(vector<T>& a) {
        for (T& i : a) {
            (*this) >> i;
        }
        return *this;
    }
} f_reader;

struct fast_writer {
    template<typename T>
    fast_writer& operator<<(T n) {
        writeInt(n); return *this;
    }
	fast_writer& operator<<(double n) {
		writeDouble(n); return *this;
	}
	fast_writer& operator<<(float n) {
		writeDouble(n); return *this;
	}
    fast_writer& operator<<(const string& s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(const char* s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(char c) {
        writeChar(c); return *this;
    }
    template<typename T>
    fast_writer& operator<<(const vector<T>& a) {
        for (size_t i = 0; i < a.size(); ++i) {
            if (i) {
                (*this) << ' ';
            }
            (*this) << a[i];
        }
        return *this;
    }
    void flush() {
        ::flush();
    }
} f_writer;

#define cin f_reader
#define cout f_writer

#pragma GCC diagnostic pop
#endif //_LIB_FASTIO_

int main(int argc, char** argv) {
#ifdef VSE
    if (argc > 1) assert(freopen(argv[1], "r", stdin));
    rng.seed(0);
#endif
#ifndef cin
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#endif

    struct point {
        llong x, y;

        point operator+(point p) {
            return point{x + p.x, y + p.y};
        }
    };

    point s, t;
    cin >> s.x >> s.y >> t.x >> t.y;

    int n;
    string a;
    cin >> n >> a;

    auto move = [](point& p, char c) {
        if (c == 'U') {
            p.y++;
        } else if (c == 'D') {
            p.y--;
        } else if (c == 'L') {
            p.x--;
        } else {
            p.x++;
        }
    };

    point o = {0, 0};

    for (int i = 0; i < n; i++) {
        move(o, a[i]);
    }

    auto dist = [](point a, point b) {
        return abs(a.x - b.x) + abs(a.y - b.y);
    };

    llong ans = 0;
    point c = s;

    if (dist(s + o, t) > n) {
        llong d1 = dist(s, t);
        llong d2 = dist(s + o, t) - n;
        if (d1 == d2) {
            cout << -1;
            return 0;
        }

        llong x = max(0LL, d1 / (d1 - d2) - 1);

        ans = x * n;
        c = {s.x + o.x * x, s.y + o.y * x};
    }

    int i = 0;

    while (dist(c, t) > ans) {
        move(c, a[ans % n]);
        ans++;
        i++;
        if (i > 100 * n) {
            cout << -1;
            return 0;
            // cout << s.x << " " << s.y << "\n";
            // cout << t.x << " " << t.y << "\n";
            // cout << o.x << " " << o.y << "\n";
            // cout << c.x << " " << c.y << "\n";
            // cout << ans << "\n";
            // return 0;
        }
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

template <typename K, typename V = __gnu_pbds::null_type>
using tree = __gnu_pbds::tree<K, V, less<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
using llong = long long;
auto isz = [](const auto& c) { return int(c.size()); };
mt19937 rng((size_t) make_shared<char>().get());

#ifndef _LIB_FASTIO_
#define _LIB_FASTIO_

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
#pragma GCC diagnostic ignored "-Wconversion"

/** Fast allocation */

#ifdef FAST_ALLOCATOR_MEMORY
	int allocator_pos = 0;
	char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
	inline void * operator new ( size_t n ) {
		char *res = allocator_memory + allocator_pos;
		allocator_pos += n;
		assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
		return (void *)res;
	}
	inline void operator delete ( void * ) noexcept { }
	//inline void * operator new [] ( size_t ) { assert(0); }
	//inline void operator delete [] ( void * ) { assert(0); }
#endif

/** Fast input-output */

/** Read */

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
	if (buf_pos == buf_len) {
		buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
		if (buf_pos == buf_len)
			return 1;
	}
	return 0;
}

inline int getChar() {
	return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
	return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
	int c;
	while ((c = peekChar()) != -1 && c <= 32)
		buf_pos++;
	return c == -1;
}

inline void skipBlanks() {
	while (!isEof() && buf[buf_pos] <= 32U)
		buf_pos++;
}

inline int readChar() {
	int c = getChar();
	while (c != -1 && c <= 32)
		c = getChar();
	return c;
}

inline unsigned int readUInt() {
	int c = readChar();
	unsigned int x = 0;
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return x;
}

template <class T = int>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	else if (c == '+')
		c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

inline long long readLong() {
	return readInt<long long>();
}

inline double readDouble() {
	int s = 1, c = readChar();
	double x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	if (c == '.') {
		c = getChar();
		double coef = 1;
		while ('0' <= c && c <= '9')
			x += (c - '0') * (coef *= 1e-1), c = getChar();
	}
	return s == 1 ? x : -x;
}

inline void readWord( char *s ) {
	int c = readChar();
	while (c > 32)
		*s++ = c, c = getChar();
	*s = 0;
}

inline void readWord( string &s ) {
	s.clear();
	int c = readChar();
	while (c > 32)
		s += c, c = getChar();
}

inline bool readLine( char *s ) {
	int c = getChar();
	while (c != '\n' && c != -1)
		*s++ = c, c = getChar();
	*s = 0;
	return c != -1;
}

inline bool readLine( string &s ) {
	s.clear();
	int c = getChar();
	while (c != '\n' && c != -1)
		s += c, c = getChar();
	return c != -1;
}

/** Write */

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_buf_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
	write_buf[write_buf_pos++] = x;
}

inline void flush() {
	if (write_buf_pos) {
		fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
		fflush(stdout);
	}
}

template <class T>
inline void writeInt( T x, char end = 0, int output_len = -1) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n < output_len)
		s[n++] = '0';
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

inline void writeWord(const string& s) {
	writeWord(s.c_str());
}

inline void writeDouble( double x, int output_len = 0) {
	if (x < 0)
		writeChar('-'), x = -x;
	int t = (int)x;
	writeInt(t), x -= t;
	writeChar('.');
	for (int i = output_len - 1; i > 0; i--) {
		x *= 10;
		t = std::min(9, (int)x);
		writeChar('0' + t), x -= t;
	}
	x *= 10;
	t = std::min(9, (int)(x + 0.5));
	writeChar('0' + t);
}

/** Buffer flusher */

static struct buffer_flusher_t {
	~buffer_flusher_t() {
		flush();
	}
} buffer_flusher;

/** Reader and writer */

struct fast_reader {
    fast_reader& operator>>(int& n) {
        n = readInt(); return *this;
    }
    fast_reader& operator>>(unsigned int& n) {
        n = readUInt(); return *this;
    }
    fast_reader& operator>>(llong& n) {
        n = readLong(); return *this;
    }
	fast_reader& operator>>(double& n) {
        n = readDouble(); return *this;
    }
	fast_reader& operator>>(float& n) {
        n = (float) readDouble(); return *this;
    }
    fast_reader& operator>>(string& s) {
        readWord(s); return *this;
    }
    fast_reader& operator>>(char& c) {
        c = (char) readChar(); return *this;
    }
    template<typename T>
    fast_reader& operator>>(vector<T>& a) {
        for (T& i : a) {
            (*this) >> i;
        }
        return *this;
    }
} f_reader;

struct fast_writer {
    template<typename T>
    fast_writer& operator<<(T n) {
        writeInt(n); return *this;
    }
	fast_writer& operator<<(double n) {
		writeDouble(n); return *this;
	}
	fast_writer& operator<<(float n) {
		writeDouble(n); return *this;
	}
    fast_writer& operator<<(const string& s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(const char* s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(char c) {
        writeChar(c); return *this;
    }
    template<typename T>
    fast_writer& operator<<(const vector<T>& a) {
        for (size_t i = 0; i < a.size(); ++i) {
            if (i) {
                (*this) << ' ';
            }
            (*this) << a[i];
        }
        return *this;
    }
    void flush() {
        ::flush();
    }
} f_writer;

#define cin f_reader
#define cout f_writer

#pragma GCC diagnostic pop
#endif //_LIB_FASTIO_

int main(int argc, char** argv) {
#ifdef VSE
    if (argc > 1) assert(freopen(argv[1], "r", stdin));
    rng.seed(0);
#endif
#ifndef cin
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#endif

    llong x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int n;
    string s;
    cin >> n >> s;

    auto getd = [&]() {
        return abs(x1 - x2) + abs(y1 - y2);
    };

    auto move = [&](char c) {
        if (c == 'U') {
            y1++;
        } else if (c == 'D') {
            y1--;
        } else if (c == 'L') {
            x1--;
        } else {
            x1++;
        }
    };

    llong d = getd();
    llong ox = x1, oy = y1;
    for (int i = 0; i < n; i++) {
        move(s[i]);
    }
    llong cd = getd();
    if (cd - d == n) {
        cout << -1;
        return 0;
    }

    llong x = d - (cd - n);
    llong ans = 0;
    if (x < d) {
        llong t = d / x - 1;
        t = max(t, 0LL);
        ans = t * n;
        x1 = ox + (x1 - ox) * t;
        y1 = oy + (y1 - oy) * t;
    }

    while (getd() > ans) {
        move(s[ans % n]);
        ans++;
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

template <typename K, typename V = __gnu_pbds::null_type>
using tree = __gnu_pbds::tree<K, V, less<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
using llong = long long;
auto isz = [](const auto& c) { return int(c.size()); };
mt19937 rng((size_t) make_shared<char>().get());

#ifndef _LIB_FASTIO_
#define _LIB_FASTIO_

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
#pragma GCC diagnostic ignored "-Wconversion"

/** Fast allocation */

#ifdef FAST_ALLOCATOR_MEMORY
	int allocator_pos = 0;
	char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
	inline void * operator new ( size_t n ) {
		char *res = allocator_memory + allocator_pos;
		allocator_pos += n;
		assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
		return (void *)res;
	}
	inline void operator delete ( void * ) noexcept { }
	//inline void * operator new [] ( size_t ) { assert(0); }
	//inline void operator delete [] ( void * ) { assert(0); }
#endif

/** Fast input-output */

/** Read */

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
	if (buf_pos == buf_len) {
		buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
		if (buf_pos == buf_len)
			return 1;
	}
	return 0;
}

inline int getChar() {
	return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
	return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
	int c;
	while ((c = peekChar()) != -1 && c <= 32)
		buf_pos++;
	return c == -1;
}

inline void skipBlanks() {
	while (!isEof() && buf[buf_pos] <= 32U)
		buf_pos++;
}

inline int readChar() {
	int c = getChar();
	while (c != -1 && c <= 32)
		c = getChar();
	return c;
}

inline unsigned int readUInt() {
	int c = readChar();
	unsigned int x = 0;
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return x;
}

template <class T = int>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	else if (c == '+')
		c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

inline long long readLong() {
	return readInt<long long>();
}

inline double readDouble() {
	int s = 1, c = readChar();
	double x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	if (c == '.') {
		c = getChar();
		double coef = 1;
		while ('0' <= c && c <= '9')
			x += (c - '0') * (coef *= 1e-1), c = getChar();
	}
	return s == 1 ? x : -x;
}

inline void readWord( char *s ) {
	int c = readChar();
	while (c > 32)
		*s++ = c, c = getChar();
	*s = 0;
}

inline void readWord( string &s ) {
	s.clear();
	int c = readChar();
	while (c > 32)
		s += c, c = getChar();
}

inline bool readLine( char *s ) {
	int c = getChar();
	while (c != '\n' && c != -1)
		*s++ = c, c = getChar();
	*s = 0;
	return c != -1;
}

inline bool readLine( string &s ) {
	s.clear();
	int c = getChar();
	while (c != '\n' && c != -1)
		s += c, c = getChar();
	return c != -1;
}

/** Write */

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_buf_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
	write_buf[write_buf_pos++] = x;
}

inline void flush() {
	if (write_buf_pos) {
		fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
		fflush(stdout);
	}
}

template <class T>
inline void writeInt( T x, char end = 0, int output_len = -1) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n < output_len)
		s[n++] = '0';
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

inline void writeWord(const string& s) {
	writeWord(s.c_str());
}

inline void writeDouble( double x, int output_len = 0) {
	if (x < 0)
		writeChar('-'), x = -x;
	int t = (int)x;
	writeInt(t), x -= t;
	writeChar('.');
	for (int i = output_len - 1; i > 0; i--) {
		x *= 10;
		t = std::min(9, (int)x);
		writeChar('0' + t), x -= t;
	}
	x *= 10;
	t = std::min(9, (int)(x + 0.5));
	writeChar('0' + t);
}

/** Buffer flusher */

static struct buffer_flusher_t {
	~buffer_flusher_t() {
		flush();
	}
} buffer_flusher;

/** Reader and writer */

struct fast_reader {
    fast_reader& operator>>(int& n) {
        n = readInt(); return *this;
    }
    fast_reader& operator>>(unsigned int& n) {
        n = readUInt(); return *this;
    }
    fast_reader& operator>>(llong& n) {
        n = readLong(); return *this;
    }
	fast_reader& operator>>(double& n) {
        n = readDouble(); return *this;
    }
	fast_reader& operator>>(float& n) {
        n = (float) readDouble(); return *this;
    }
    fast_reader& operator>>(string& s) {
        readWord(s); return *this;
    }
    fast_reader& operator>>(char& c) {
        c = (char) readChar(); return *this;
    }
    template<typename T>
    fast_reader& operator>>(vector<T>& a) {
        for (T& i : a) {
            (*this) >> i;
        }
        return *this;
    }
} f_reader;

struct fast_writer {
    template<typename T>
    fast_writer& operator<<(T n) {
        writeInt(n); return *this;
    }
	fast_writer& operator<<(double n) {
		writeDouble(n); return *this;
	}
	fast_writer& operator<<(float n) {
		writeDouble(n); return *this;
	}
    fast_writer& operator<<(const string& s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(const char* s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(char c) {
        writeChar(c); return *this;
    }
    template<typename T>
    fast_writer& operator<<(const vector<T>& a) {
        for (size_t i = 0; i < a.size(); ++i) {
            if (i) {
                (*this) << ' ';
            }
            (*this) << a[i];
        }
        return *this;
    }
    void flush() {
        ::flush();
    }
} f_writer;

#define cin f_reader
#define cout f_writer

#pragma GCC diagnostic pop
#endif //_LIB_FASTIO_

int main(int argc, char** argv) {
#ifdef VSE
    if (argc > 1) assert(freopen(argv[1], "r", stdin));
    rng.seed(0);
#endif
#ifndef cin
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#endif

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int n;
    string s;
    cin >> n >> s;
    int d = abs(x1 - x2) + abs(y1 - y2);
    int ox1 = x1;
    int oy1 = y1;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'U') {
            y1++;
        } else if (s[i] == 'D') {
            y1--;
        } else if (s[i] == 'L') {
            x1--;
        } else if (s[i] == 'R') {
            x1++;
        }
    }

    int cd = abs(x1 - x2) + abs(y1 - y2);
    cd = max(0, cd - n);

    if (cd == d) {
        cout << -1;
        return 0;
    }

    int x = max(0, d / (d - cd) - 1);

    llong ans = 1LL * x * n;

    x1 = ox1 + (x1 - ox1) * x;
    y1 = oy1 + (y1 - oy1) * x;

    int i = x * n;
    while (x1 != x2 || y1 != y2) {
        char c = s[i % n];
        if (c == 'U') {
            y1++;
        } else if (c == 'D') {
            y1--;
        } else if (c == 'L') {
            x1--;
        } else if (c == 'R') {
            x1++;
        }
        ans++;
        i++;
        int dd = abs(x1 - x2) + abs(y1 - y2);
        if (dd <= i) {
            break;
        }
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

template <typename K, typename V = __gnu_pbds::null_type>
using tree = __gnu_pbds::tree<K, V, less<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
using llong = long long;
auto isz = [](const auto& c) { return int(c.size()); };
mt19937 rng((size_t) make_shared<char>().get());

#ifndef _LIB_FASTIO_
#define _LIB_FASTIO_

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
#pragma GCC diagnostic ignored "-Wconversion"

/** Fast allocation */

#ifdef FAST_ALLOCATOR_MEMORY
	int allocator_pos = 0;
	char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
	inline void * operator new ( size_t n ) {
		char *res = allocator_memory + allocator_pos;
		allocator_pos += n;
		assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
		return (void *)res;
	}
	inline void operator delete ( void * ) noexcept { }
	//inline void * operator new [] ( size_t ) { assert(0); }
	//inline void operator delete [] ( void * ) { assert(0); }
#endif

/** Fast input-output */

/** Read */

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
	if (buf_pos == buf_len) {
		buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
		if (buf_pos == buf_len)
			return 1;
	}
	return 0;
}

inline int getChar() {
	return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
	return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
	int c;
	while ((c = peekChar()) != -1 && c <= 32)
		buf_pos++;
	return c == -1;
}

inline void skipBlanks() {
	while (!isEof() && buf[buf_pos] <= 32U)
		buf_pos++;
}

inline int readChar() {
	int c = getChar();
	while (c != -1 && c <= 32)
		c = getChar();
	return c;
}

inline unsigned int readUInt() {
	int c = readChar();
	unsigned int x = 0;
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return x;
}

template <class T = int>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	else if (c == '+')
		c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

inline long long readLong() {
	return readInt<long long>();
}

inline double readDouble() {
	int s = 1, c = readChar();
	double x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	if (c == '.') {
		c = getChar();
		double coef = 1;
		while ('0' <= c && c <= '9')
			x += (c - '0') * (coef *= 1e-1), c = getChar();
	}
	return s == 1 ? x : -x;
}

inline void readWord( char *s ) {
	int c = readChar();
	while (c > 32)
		*s++ = c, c = getChar();
	*s = 0;
}

inline void readWord( string &s ) {
	s.clear();
	int c = readChar();
	while (c > 32)
		s += c, c = getChar();
}

inline bool readLine( char *s ) {
	int c = getChar();
	while (c != '\n' && c != -1)
		*s++ = c, c = getChar();
	*s = 0;
	return c != -1;
}

inline bool readLine( string &s ) {
	s.clear();
	int c = getChar();
	while (c != '\n' && c != -1)
		s += c, c = getChar();
	return c != -1;
}

/** Write */

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_buf_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
	write_buf[write_buf_pos++] = x;
}

inline void flush() {
	if (write_buf_pos) {
		fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
		fflush(stdout);
	}
}

template <class T>
inline void writeInt( T x, char end = 0, int output_len = -1) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n < output_len)
		s[n++] = '0';
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

inline void writeWord(const string& s) {
	writeWord(s.c_str());
}

inline void writeDouble( double x, int output_len = 0) {
	if (x < 0)
		writeChar('-'), x = -x;
	int t = (int)x;
	writeInt(t), x -= t;
	writeChar('.');
	for (int i = output_len - 1; i > 0; i--) {
		x *= 10;
		t = std::min(9, (int)x);
		writeChar('0' + t), x -= t;
	}
	x *= 10;
	t = std::min(9, (int)(x + 0.5));
	writeChar('0' + t);
}

/** Buffer flusher */

static struct buffer_flusher_t {
	~buffer_flusher_t() {
		flush();
	}
} buffer_flusher;

/** Reader and writer */

struct fast_reader {
    fast_reader& operator>>(int& n) {
        n = readInt(); return *this;
    }
    fast_reader& operator>>(unsigned int& n) {
        n = readUInt(); return *this;
    }
    fast_reader& operator>>(llong& n) {
        n = readLong(); return *this;
    }
	fast_reader& operator>>(double& n) {
        n = readDouble(); return *this;
    }
	fast_reader& operator>>(float& n) {
        n = (float) readDouble(); return *this;
    }
    fast_reader& operator>>(string& s) {
        readWord(s); return *this;
    }
    fast_reader& operator>>(char& c) {
        c = (char) readChar(); return *this;
    }
    template<typename T>
    fast_reader& operator>>(vector<T>& a) {
        for (T& i : a) {
            (*this) >> i;
        }
        return *this;
    }
} f_reader;

struct fast_writer {
    template<typename T>
    fast_writer& operator<<(T n) {
        writeInt(n); return *this;
    }
	fast_writer& operator<<(double n) {
		writeDouble(n); return *this;
	}
	fast_writer& operator<<(float n) {
		writeDouble(n); return *this;
	}
    fast_writer& operator<<(const string& s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(const char* s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(char c) {
        writeChar(c); return *this;
    }
    template<typename T>
    fast_writer& operator<<(const vector<T>& a) {
        for (size_t i = 0; i < a.size(); ++i) {
            if (i) {
                (*this) << ' ';
            }
            (*this) << a[i];
        }
        return *this;
    }
    void flush() {
        ::flush();
    }
} f_writer;

#define cin f_reader
#define cout f_writer

#pragma GCC diagnostic pop
#endif //_LIB_FASTIO_

int main(int argc, char** argv) {
#ifdef VSE
    if (argc > 1) assert(freopen(argv[1], "r", stdin));
    rng.seed(0);
#endif
#ifndef cin
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#endif

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int n;
    string s;
    cin >> n >> s;
    int d = abs(x1 - x2) + abs(y1 - y2);
    int ox1 = x1;
    int oy1 = y1;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'U') {
            y1++;
        } else if (s[i] == 'D') {
            y1--;
        } else if (s[i] == 'L') {
            x1--;
        } else if (s[i] == 'R') {
            x1++;
        }
    }

    int cd = abs(x1 - x2) + abs(y1 - y2);
    cd = max(0, cd - n);

    if (cd == d) {
        cout << -1;
        return 0;
    }

    int x = max(0, d / (d - cd) - 1);

    llong ans = 1LL * x * n;

    x1 = ox1 + (x1 - ox1) * x;
    y1 = oy1 + (y1 - oy1) * x;

    llong i = 1LL * x * n;
    while (x1 != x2 || y1 != y2) {
        char c = s[i % n];
        if (c == 'U') {
            y1++;
        } else if (c == 'D') {
            y1--;
        } else if (c == 'L') {
            x1--;
        } else if (c == 'R') {
            x1++;
        }
        ans++;
        i++;
        int dd = abs(x1 - x2) + abs(y1 - y2);
        if (dd <= i) {
            break;
        }
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

template <typename K, typename V = __gnu_pbds::null_type>
using tree = __gnu_pbds::tree<K, V, less<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
using llong = long long;
auto isz = [](const auto& c) { return int(c.size()); };
mt19937 rng((size_t) make_shared<char>().get());

#ifndef _LIB_FASTIO_
#define _LIB_FASTIO_

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
#pragma GCC diagnostic ignored "-Wconversion"

/** Fast allocation */

#ifdef FAST_ALLOCATOR_MEMORY
	int allocator_pos = 0;
	char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
	inline void * operator new ( size_t n ) {
		char *res = allocator_memory + allocator_pos;
		allocator_pos += n;
		assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
		return (void *)res;
	}
	inline void operator delete ( void * ) noexcept { }
	//inline void * operator new [] ( size_t ) { assert(0); }
	//inline void operator delete [] ( void * ) { assert(0); }
#endif

/** Fast input-output */

/** Read */

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
	if (buf_pos == buf_len) {
		buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
		if (buf_pos == buf_len)
			return 1;
	}
	return 0;
}

inline int getChar() {
	return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
	return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
	int c;
	while ((c = peekChar()) != -1 && c <= 32)
		buf_pos++;
	return c == -1;
}

inline void skipBlanks() {
	while (!isEof() && buf[buf_pos] <= 32U)
		buf_pos++;
}

inline int readChar() {
	int c = getChar();
	while (c != -1 && c <= 32)
		c = getChar();
	return c;
}

inline unsigned int readUInt() {
	int c = readChar();
	unsigned int x = 0;
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return x;
}

template <class T = int>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	else if (c == '+')
		c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

inline long long readLong() {
	return readInt<long long>();
}

inline double readDouble() {
	int s = 1, c = readChar();
	double x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	if (c == '.') {
		c = getChar();
		double coef = 1;
		while ('0' <= c && c <= '9')
			x += (c - '0') * (coef *= 1e-1), c = getChar();
	}
	return s == 1 ? x : -x;
}

inline void readWord( char *s ) {
	int c = readChar();
	while (c > 32)
		*s++ = c, c = getChar();
	*s = 0;
}

inline void readWord( string &s ) {
	s.clear();
	int c = readChar();
	while (c > 32)
		s += c, c = getChar();
}

inline bool readLine( char *s ) {
	int c = getChar();
	while (c != '\n' && c != -1)
		*s++ = c, c = getChar();
	*s = 0;
	return c != -1;
}

inline bool readLine( string &s ) {
	s.clear();
	int c = getChar();
	while (c != '\n' && c != -1)
		s += c, c = getChar();
	return c != -1;
}

/** Write */

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_buf_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
	write_buf[write_buf_pos++] = x;
}

inline void flush() {
	if (write_buf_pos) {
		fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
		fflush(stdout);
	}
}

template <class T>
inline void writeInt( T x, char end = 0, int output_len = -1) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n < output_len)
		s[n++] = '0';
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

inline void writeWord(const string& s) {
	writeWord(s.c_str());
}

inline void writeDouble( double x, int output_len = 0) {
	if (x < 0)
		writeChar('-'), x = -x;
	int t = (int)x;
	writeInt(t), x -= t;
	writeChar('.');
	for (int i = output_len - 1; i > 0; i--) {
		x *= 10;
		t = std::min(9, (int)x);
		writeChar('0' + t), x -= t;
	}
	x *= 10;
	t = std::min(9, (int)(x + 0.5));
	writeChar('0' + t);
}

/** Buffer flusher */

static struct buffer_flusher_t {
	~buffer_flusher_t() {
		flush();
	}
} buffer_flusher;

/** Reader and writer */

struct fast_reader {
    fast_reader& operator>>(int& n) {
        n = readInt(); return *this;
    }
    fast_reader& operator>>(unsigned int& n) {
        n = readUInt(); return *this;
    }
    fast_reader& operator>>(llong& n) {
        n = readLong(); return *this;
    }
	fast_reader& operator>>(double& n) {
        n = readDouble(); return *this;
    }
	fast_reader& operator>>(float& n) {
        n = (float) readDouble(); return *this;
    }
    fast_reader& operator>>(string& s) {
        readWord(s); return *this;
    }
    fast_reader& operator>>(char& c) {
        c = (char) readChar(); return *this;
    }
    template<typename T>
    fast_reader& operator>>(vector<T>& a) {
        for (T& i : a) {
            (*this) >> i;
        }
        return *this;
    }
} f_reader;

struct fast_writer {
    template<typename T>
    fast_writer& operator<<(T n) {
        writeInt(n); return *this;
    }
	fast_writer& operator<<(double n) {
		writeDouble(n); return *this;
	}
	fast_writer& operator<<(float n) {
		writeDouble(n); return *this;
	}
    fast_writer& operator<<(const string& s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(const char* s) {
        writeWord(s); return *this;
    }
    fast_writer& operator<<(char c) {
        writeChar(c); return *this;
    }
    template<typename T>
    fast_writer& operator<<(const vector<T>& a) {
        for (size_t i = 0; i < a.size(); ++i) {
            if (i) {
                (*this) << ' ';
            }
            (*this) << a[i];
        }
        return *this;
    }
    void flush() {
        ::flush();
    }
} f_writer;

#define cin f_reader
#define cout f_writer

#pragma GCC diagnostic pop
#endif //_LIB_FASTIO_

int main(int argc, char** argv) {
#ifdef VSE
    if (argc > 1) assert(freopen(argv[1], "r", stdin));
    rng.seed(0);
#endif
#ifndef cin
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#endif

    struct point {
        llong x, y;

        point operator+(point p) {
            return point{x + p.x, y + p.y};
        }
    };

    point s, t;
    cin >> s.x >> s.y >> t.x >> t.y;

    int n;
    string a;
    cin >> n >> a;

    auto move = [](point& p, char c) {
        if (c == 'U') {
            p.y++;
        } else if (c == 'D') {
            p.y--;
        } else if (c == 'L') {
            p.x--;
        } else {
            p.x++;
        }
    };

    point o = {0, 0};

    for (int i = 0; i < n; i++) {
        move(o, a[i]);
    }

    auto dist = [](point a, point b) {
        return abs(a.x - b.x) + abs(a.y - b.y);
    };

    llong ans = 0;
    point c = s;

    if (dist(s + o, t) > n) {
        llong d1 = dist(s, t);
        llong d2 = dist(s + o, t) - n;
        if (d1 == d2) {
            cout << -1;
            return 0;
        }

        llong x = max(0LL, d1 / (d1 - d2));

        ans = x * n;
        c = {s.x + o.x * x, s.y + o.y * x};
    }

    while (dist(c, t) > ans) {
        move(c, a[ans % n]);
        ans++;
    }

    cout << ans << "\n";

    return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		if(s[i]=='D') d++;
		if(s[i]=='L') l++;
		if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		if(s[i]=='D') td++;
		if(s[i]=='L') tl++;
		if(s[i]=='R') tr++;
	}
	l=0; r=2e9+5;
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	if(check(r)) cout<<r<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		if(s[i]=='D') d++;
		if(s[i]=='L') l++;
		if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		if(s[i]=='D') td++;
		if(s[i]=='L') tl++;
		if(s[i]=='R') tr++;
	}
	l=0; r=2*(abs(xs-xe)+abs(ys-ye));
	while(l<r){

		mid=(l+r)/2;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		if(s[i]=='D') d++;
		if(s[i]=='L') l++;
		if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		if(s[i]=='D') td++;
		if(s[i]=='L') tl++;
		if(s[i]=='R') tr++;
	}
	l=0; r=2*(abs(xs-xe)+abs(ys-ye));
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else if(check(l+1)) cout<<l+1<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		if(s[i]=='D') d++;
		if(s[i]=='L') l++;
		if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		if(s[i]=='D') td++;
		if(s[i]=='L') tl++;
		if(s[i]=='R') tr++;
	}
	l=0; r=2*(abs(xs-xe)+abs(ys-ye));
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	if(check(r)) cout<<r<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
ll xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
ll ab(ll a){
	if(a<0) return 0LL-a;
	else return a;
}
bool check(ll k){
	ll v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		else if(s[i]=='D') d++;
		else if(s[i]=='L') l++;
		else if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=ab(xm-xe)+ab(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	ll i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		else if(s[i]=='D') td++;
		else if(s[i]=='L') tl++;
		else if(s[i]=='R') tr++;
	}
	l=0; r=1e18;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else if(check(l+1)) cout<<l+1<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
ll xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		else if(s[i]=='D') d++;
		else if(s[i]=='L') l++;
		else if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		else if(s[i]=='D') td++;
		else if(s[i]=='L') tl++;
		else if(s[i]=='R') tr++;
	}
	l=0; r=1e18;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else if(check(l+1)) cout<<l+1<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		else if(s[i]=='D') d++;
		else if(s[i]=='L') l++;
		else if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		else if(s[i]=='D') td++;
		else if(s[i]=='L') tl++;
		else if(s[i]=='R') tr++;
	}
	l=0; r=(abs(xs-xe)+abs(ys-ye));
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else if(check(l+1)) cout<<l+1<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		if(s[i]=='D') d++;
		if(s[i]=='L') l++;
		if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		if(s[i]=='D') td++;
		if(s[i]=='L') tl++;
		if(s[i]=='R') tr++;
	}
	l=0; r=2*(abs(xs-xe)+abs(ys-ye));
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		else if(s[i]=='D') d++;
		else if(s[i]=='L') l++;
		else if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		else if(s[i]=='D') td++;
		else if(s[i]=='L') tl++;
		else if(s[i]=='R') tr++;
	}
	l=0; r=2*(abs(xs-xe)+abs(ys-ye));
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else if(check(l+1)) cout<<l+1<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		else if(s[i]=='D') d++;
		else if(s[i]=='L') l++;
		else if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		else if(s[i]=='D') td++;
		else if(s[i]=='L') tl++;
		else if(s[i]=='R') tr++;
	}
	l=0; r=1e18;
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else if(check(l+1)) cout<<l+1<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		else if(s[i]=='D') d++;
		else if(s[i]=='L') l++;
		else if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		else if(s[i]=='D') td++;
		else if(s[i]=='L') tl++;
		else if(s[i]=='R') tr++;
	}
	l=0; r=(abs(xs-xe)+abs(ys-ye))+5;
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	if(check(l)) cout<<l<<"\n";
	else if(check(l+1)) cout<<l+1<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb_ push_back
#define pf_ push_front
#define mp_ make_pair
#define ins_ insert
#define rsz_ resize
#define clr_ clear
#define itr_ iterator
#define lb_ lower_bound
#define ub_ upper_bound
#define len_ length
#define fir first
#define sec second

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
int xs,ys,xe,ye,xm,ym,tu,td,tl,tr,n,l,r,mid,dis;
string s;
int abs(int a){
	if(a<0) return 0-a;
	else return a;
}
bool check(int k){
	int v,w,l,r,u,d;
	w=k/n;
	v=k%n;
	u=d=l=r=0;
	for(int i=0;i<v;i++){
		if(s[i]=='U') u++;
		if(s[i]=='D') d++;
		if(s[i]=='L') l++;
		if(s[i]=='R') r++;
	}
	l+=tl*w;
	r+=tr*w;
	u+=tu*w;
	d+=td*w;
	xm=xs+r-l;
	ym=ys+u-d;
	dis=abs(xm-xe)+abs(ym-ye);

	if(k>=dis)return true;
	else return false;
}
int main(){
	IOS;
	int i;
	cin>>xs;cin>>ys;cin>>xe;cin>>ye;
	cin>>n>>s;

	tl=tu=tr=td=0;
	for(i=0;i<n;i++){
		if(s[i]=='U') tu++;
		if(s[i]=='D') td++;
		if(s[i]=='L') tl++;
		if(s[i]=='R') tr++;
	}
	l=0; r=abs(xs-xe)+abs(ys-ye);
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	if(check(r)) cout<<r<<"\n";
	else cout<<"-1\n";
	return 0;
}


//
// Created by Ajay on 5/11/2019.
//
#include <bits/stdc++.h>
using namespace std;
#define N 100000+10
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f
/*
 * binary search
 */
// Find the smallest X such that f(X) is true;
ll binarysearch(function<bool(ll)> f) {
  ll lo = 0;
  ll hi = 500000000000000;
//  cout << hi << endl;
//  cout << numeric_limits<ll>::max() << endl;
//  cout << INF << endl;
//  cout << 50000000000000 << endl;
  ll bestSoFar = -1;
  // Range [lo, hi];
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (f(mid)) {
      bestSoFar = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return bestSoFar;
}

bool canReach(ll day);
ll n; ll cx, cy, dx, dy;
ll cumx[N]; ll cumy[N];

int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin>>cx>>cy;
  cin>>dx>>dy;
  cin>>n;
  string s; cin >> s;
  cumx[0] = 0;
  cumy[0] = 0;
  for(int i = 1; i <= n; ++i) {
    char c = s[i-1];
    if(c == 'U') {
      cumy[i]+=cumy[i-1]+1;
    } else if (c == 'D') {
      cumy[i]+=cumy[i-1]-1;
    } else if (c == 'L') {
      cumy[i]+=cumx[i-1]-1;
    } else if (c == 'R') {
      cumy[i]+=cumx[i-1]+1;
    }
  }
  cout <<binarysearch(canReach) << "\n";
}

bool canReach(ll day) {
//  cout << day << endl;
  ll moves = day;
  // find the total effect of forecasts
  ll fx = 0; ll fy = 0;
  fx+=floor(day/n) * cumx[n];
  fy+=floor(day/n) * cumy[n];
//  while(day >= n) {
//    day -= n;
//    fx+=cumx[n];
//    fy+=cumy[n];
//  }
  fx+=cumx[day%n];
  fy+=cumy[day%n];

  ll newx = cx + fx; ll newy = cy+fy;
  if(abs(newx-dx) + abs(newy-dy) <= moves) {
    return true;
  } else {
    return false;
  }
}


//
// Created by Ajay on 5/11/2019.
//
#include <bits/stdc++.h>
using namespace std;
#define N 100000+10
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f
/*
 * binary search
 */
// Find the smallest X such that f(X) is true;
ll binarysearch(function<bool(ll)> f) {
  ll lo = 0;
  ll hi = 1e18;
  ll bestSoFar = -1;
  // Range [lo, hi];
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (f(mid)) {
      bestSoFar = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return bestSoFar;
}

bool canReach(ll day);
ll n; ll cx, cy, dx, dy;
ll cumx[N]; ll cumy[N];

int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin>>cx>>cy;
  cin>>dx>>dy;
  cin>>n;
  string s; cin >> s;
  cumx[0] = 0;
  cumy[0] = 0;
  for(ll i = 1; i <= n; ++i) {
    char c = s[i-1];
    if(c == 'U') {
      cumy[i]=cumy[i-1]+1;
    } else if (c == 'D') {
      cumy[i]=cumy[i-1]-1;
    } else if (c == 'L') {
      cumy[i]=cumx[i-1]-1;
    } else if (c == 'R') {
      cumy[i]=cumx[i-1]+1;
    }
  }
  ll result = binarysearch(canReach);
  if(result > 100000*2e9) {
//    cout << 50000000000000 << endl;
//    cout << 1LL*100000*2000000000 << endl;
    cout << -1 << endl;
  } else {
    cout <<result << "\n";
  }
}

bool canReach(ll day) {
//  cout << day << endl;
  ll moves = day;
  // find the total effect of forecasts
  ll fx = cx; ll fy = cy;
  fx+=floor(day/n) * cumx[n];
  fy+=floor(day/n) * cumy[n];
  fx+=cumx[day%n];
  fy+=cumy[day%n];

  ll newx = fx; ll newy = fy;
//  if(abs(newx-dx) <= moves) {
  if((abs(newx-dx) + abs(newy-dy)) <= moves) {
    return true;
  } else {
    return false;
  }
}


//
// Created by Ajay on 5/11/2019.
//
#include <bits/stdc++.h>
using namespace std;
#define N 100000+10

/*
 * binary search
 */
// Find the smallest X such that f(X) is true;
int binarysearch(function<bool(int)> f) {
  int lo = 0;
  int hi = 100000*10000;
  int bestSoFar = -1;
  // Range [lo, hi];
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (f(mid)) {
      bestSoFar = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return bestSoFar;
}

bool canReach(int day);
int n; int cx, cy, dx, dy;
int cumx[N]; int cumy[N];

int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin>>cx>>cy;
  cin>>dx>>dy;
  cin>>n;
  string s; cin >> s;
  cumx[0] = 0;
  cumy[0] = 0;
  for(int i = 1; i <= n; ++i) {
    char c = s[i-1];
    if(c == 'U') {
      cumy[i]+=cumy[i-1]+1;
    } else if (c == 'D') {
      cumy[i]+=cumy[i-1]-1;
    } else if (c == 'L') {
      cumy[i]+=cumx[i-1]-1;
    } else if (c == 'R') {
      cumy[i]+=cumx[i-1]+1;
    }
  }
  cout <<binarysearch(canReach) << "\n";
}

bool canReach(int day) {
  int moves = day;
  // find the total effect of forecasts
  int fx = 0; int fy = 0;
  fx+=floor(day/n) * cumx[n];
  fy+=floor(day/n) * cumy[n];
//  while(day >= n) {
//    day -= n;
//    fx+=cumx[n];
//    fy+=cumy[n];
//  }
  fx+=cumx[day%n];
  fy+=cumy[day%n];

  int newx = cx + fx; int newy = cy+fy;
  if(abs(newx-dx) + abs(newy-dy) <= moves) {
    return true;
  } else {
    return false;
  }
}


//
// Created by Ajay on 5/11/2019.
//
#include <bits/stdc++.h>
using namespace std;
#define N 100000+10
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f
/*
 * binary search
 */
// Find the smallest X such that f(X) is true;
ll binarysearch(function<bool(ll)> f) {
  ll lo = 0;
  ll hi = 5000000000000000;
//  cout << hi << endl;
//  cout << numeric_limits<ll>::max() << endl;
//  cout << INF << endl;
//  cout << 50000000000000 << endl;
  ll bestSoFar = -1;
  // Range [lo, hi];
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (f(mid)) {
      bestSoFar = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return bestSoFar;
}

bool canReach(ll day);
ll n; ll cx, cy, dx, dy;
ll cumx[N]; ll cumy[N];

int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin>>cx>>cy;
  cin>>dx>>dy;
  cin>>n;
  string s; cin >> s;
  cumx[0] = 0;
  cumy[0] = 0;
  for(int i = 1; i <= n; ++i) {
    char c = s[i-1];
    if(c == 'U') {
      cumy[i]+=cumy[i-1]+1;
    } else if (c == 'D') {
      cumy[i]+=cumy[i-1]-1;
    } else if (c == 'L') {
      cumy[i]+=cumx[i-1]-1;
    } else if (c == 'R') {
      cumy[i]+=cumx[i-1]+1;
    }
  }
  cout <<binarysearch(canReach) << "\n";
}

bool canReach(ll day) {
//  cout << day << endl;
  ll moves = day;
  // find the total effect of forecasts
  ll fx = 0; ll fy = 0;
  fx+=floor(day/n) * cumx[n];
  fy+=floor(day/n) * cumy[n];
//  while(day >= n) {
//    day -= n;
//    fx+=cumx[n];
//    fy+=cumy[n];
//  }
  fx+=cumx[day%n];
  fy+=cumy[day%n];

  ll newx = cx + fx; ll newy = cy+fy;
  if(abs(newx-dx) + abs(newy-dy) <= moves) {
    return true;
  } else {
    return false;
  }
}


//
// Created by Ajay on 5/11/2019.
//
#include <bits/stdc++.h>
using namespace std;
#define N 100000+10
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f

ll n; ll cx, cy, dx, dy;
ll cumx[N]; ll cumy[N];

/*
 * binary search
 */
// Find the smallest X such that f(X) is true;
ll binarysearch(function<bool(ll)> f) {
  ll lo = 0;
  ll hi = 1e18;
  ll bestSoFar = -1;
  // Range [lo, hi];
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (f(mid)) {
      bestSoFar = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return bestSoFar;
}

//ll binarysearch2() {
//  ll l = 0, r = 1e18;
//  while(r-l>1) {
//    ll day = (l+r)/2;
//    ll fx; ll fy;
//    fx = cx + (day/n) * cumx[n];
//    fy = cy + (day/n) * cumy[n];
//    fx+=cumx[day%n];
//    fy+=cumy[day%n];
//    if((abs(fx-dx) + abs(fy-dy)) <= day) {
//      r = day;
//    } else {
//      l = day;
//    }
//  }
//  if(r > 5e15) r = -1;
//  cout << r << endl;
//  return 0;
//}

bool canReach(ll day);

int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin>>cx>>cy;
  cin>>dx>>dy;
  cin>>n;
  string s; cin >> s;
  cumx[0] = 0;
  cumy[0] = 0;
  for(ll i = 1; i <= n; ++i) {
    char c = s[i-1];
    if(c == 'U') {
      cumy[i]=cumy[i-1]+1;
      cumx[i]=cumx[i-1];
    } else if (c == 'D') {
      cumy[i]=cumy[i-1]-1;
      cumx[i]=cumx[i-1];
    } else if (c == 'L') {
      cumx[i]=cumx[i-1]-1;
      cumy[i]=cumy[i-1];
    } else if (c == 'R') {
      cumx[i]=cumx[i-1]+1;
      cumy[i]=cumy[i-1];
    }
  }
//  binarysearch2();

  ll result = binarysearch(canReach);
  if(result > 100000*2e9) {
//    cout << 50000000000000 << endl;
//    cout << 1LL*100000*2000000000 << endl;
    cout << -1 << endl;
  } else {
    cout <<result << "\n";
  }
}

bool canReach(ll day) {
//  cout << day << endl;
  ll moves = day;
  // find the total effect of forecasts
  ll fx; ll fy;
  fx = cx + (day/n) * cumx[n];
  fy = cy + (day/n) * cumy[n];
  fx+=cumx[day%n];
  fy+=cumy[day%n];

//  if(abs(newx-dx) <= moves) {
  if((abs(fx-dx) + abs(fy-dy)) <= moves) {
    return true;
  } else {
    return false;
  }
}


//
// Created by Ajay on 5/11/2019.
//
#include <bits/stdc++.h>
using namespace std;
#define N 100000+10
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f

ll n; ll cx, cy, dx, dy;
ll cumx[N]; ll cumy[N];

/*
 * binary search
 */
// Find the smallest X such that f(X) is true;
ll binarysearch(function<bool(ll)> f) {
  ll lo = 0;
  ll hi = 1e18;
  ll bestSoFar = -1;
  // Range [lo, hi];
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (f(mid)) {
      bestSoFar = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return bestSoFar;
}

ll binarysearch2() {
  ll l = 0, r = 1e18;
  while(r-l>1) {
    ll day = (l+r)/2;
    ll fx; ll fy;
    fx = cx + (day/n) * cumx[n];
    fy = cy + (day/n) * cumy[n];
    fx+=cumx[day%n];
    fy+=cumy[day%n];
    if((abs(fx-dx) + abs(fy-dy)) <= day) {
      r = day;
    } else {
      l = day;
    }
  }
  if(r > 5e15) r = -1;
  cout << r << endl;
}

bool canReach(ll day);

int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin>>cx>>cy;
  cin>>dx>>dy;
  cin>>n;
  string s; cin >> s;
  cumx[0] = 0;
  cumy[0] = 0;
  for(ll i = 1; i <= n; ++i) {
    char c = s[i-1];
    if(c == 'U') {
      cumy[i]=cumy[i-1]+1;
    } else if (c == 'D') {
      cumy[i]=cumy[i-1]-1;
    } else if (c == 'L') {
      cumx[i]=cumx[i-1]-1;
    } else if (c == 'R') {
      cumx[i]=cumx[i-1]+1;
    }
  }
  binarysearch2();

//  ll result = binarysearch(canReach);
//  if(result > 100000*2e9) {
////    cout << 50000000000000 << endl;
////    cout << 1LL*100000*2000000000 << endl;
//    cout << -1 << endl;
//  } else {
//    cout <<result << "\n";
//  }
}

bool canReach(ll day) {
//  cout << day << endl;
  ll moves = day;
  // find the total effect of forecasts
  ll fx; ll fy;
  fx = cx + (day/n) * cumx[n];
  fy = cy + (day/n) * cumy[n];
  fx+=cumx[day%n];
  fy+=cumy[day%n];

//  if(abs(newx-dx) <= moves) {
  if((abs(fx-dx) + abs(fy-dy)) <= moves) {
    return true;
  } else {
    return false;
  }
}


import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class round149C {
static class struct{
    myPoint p;
    int cost;
    public struct(myPoint pp, int c){
        p = pp;
        cost = c;
    }
}
static class myPoint{
    long x, y;
    public myPoint(long xx, long yy){
        x = xx;
        y = yy;
    }
    public int hashCode(){
        return (int)(x + 101*y);
    }
    public boolean equals(Object o){
        myPoint p = (myPoint)o;
        return x == p.x && y == p.y;
    }
}
    static HashMap<myPoint, Integer> map = new HashMap<myPoint, Integer>();
    static int [] dp;
    static myPoint p2;
    static int [] dx = new int []{1,-1,0,0,-1,-1,1,1};
    static int [] dy = new int []{0,0,1,-1,-1,1,-1,1};
    static boolean [] vis;
    public static int runBFS(myPoint st){
        Queue<struct> bfs = new LinkedList<round149C.struct>();
        bfs.offer(new struct(st, 0));
        vis = new boolean [map.size() + 2];
        while(!bfs.isEmpty()){
            struct p = bfs.poll();
            if(p.p.equals(p2))
                return p.cost;
            if(vis[map.get(p.p)]){
                continue;
            }
            vis[map.get(p.p)] = true;
            for(int i = 0 ; i < 8 ; ++i){
                long nx = p.p.x + dx[i];
                long ny = p.p.y + dy[i];
                if(nx < 1 || ny < 1 || nx > 1e9 || ny > 1e9)
                    continue;
                myPoint nxt = new myPoint(nx, ny);
                if(map.containsKey(nxt)){
                    bfs.offer(new struct(nxt, p.cost + 1));
                }

            }
        }
        return -1;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long xi = sc.nextLong();
        long yi = sc.nextLong();
        long xe = sc.nextLong();
        long ye = sc.nextLong();
        int n = sc.nextInt();
        myPoint p1 = new myPoint(xi, yi);
        p2 = new myPoint(xe, ye);
        for(int i = 0 ; i < n ; ++i){
            long r = sc.nextLong();
            long startc = sc.nextLong();
            long endc = sc.nextLong();
            for(long j = startc ; j <= endc ; ++j)
                map.put(new myPoint(r,j), map.size());
        }
        int ans = runBFS(p1);
        System.out.println(ans);
    }
}


import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class round149C {
static class struct{
    myPoint p;
    int cost;
    public struct(myPoint pp, int c){
        p = pp;
        cost = c;
    }
}
static class myPoint{
    long x, y;
    public myPoint(long xx, long yy){
        x = xx;
        y = yy;
    }
    public int hashCode(){
        long bits = java.lang.Double.doubleToLongBits(x);
        bits ^= java.lang.Double.doubleToLongBits(y) * 31;
        return (((int) bits) ^ ((int) (bits >> 32)));
    }
    public boolean equals(Object o){
        myPoint p = (myPoint)o;
        return x == p.x && y == p.y;
    }
}
    static HashMap<myPoint, Integer> map = new HashMap<myPoint, Integer>();
    static int [] dp;
    static myPoint p2;
    static int [] dx = new int []{1,-1,0,0,-1,-1,1,1};
    static int [] dy = new int []{0,0,1,-1,-1,1,-1,1};
    static boolean [] vis;
    public static int runBFS(myPoint st){
        Queue<struct> bfs = new LinkedList<round149C.struct>();
        bfs.offer(new struct(st, 0));
        vis = new boolean [map.size() + 2];
        while(!bfs.isEmpty()){
            struct p = bfs.poll();
            if(p.p.equals(p2))
                return p.cost;
            if(vis[map.get(p.p)]){
                continue;
            }
            vis[map.get(p.p)] = true;
            for(int i = 0 ; i < 8 ; ++i){
                long nx = p.p.x + dx[i];
                long ny = p.p.y + dy[i];
                myPoint nxt = new myPoint(nx, ny);
                if(map.containsKey(nxt)){
                    bfs.offer(new struct(nxt, p.cost + 1));
                }

            }
        }
        return -1;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long xi = sc.nextLong();
        long yi = sc.nextLong();
        long xe = sc.nextLong();
        long ye = sc.nextLong();
        int n = sc.nextInt();
        myPoint p1 = new myPoint(xi, yi);
        p2 = new myPoint(xe, ye);
        for(int i = 0 ; i < n ; ++i){
            long r = sc.nextLong();
            long startc = sc.nextLong();
            long endc = sc.nextLong();
            for(long j = startc ; j <= endc ; ++j)
                map.put(new myPoint(r,j), map.size());
        }
        int ans = runBFS(p1);
        System.out.println(ans);
    }
}


function toInt(v){ return parseInt(v); }
var _l = readline().split(' ');
var x0 = parseInt(_l[0]);
var y0 = parseInt(_l[1]);
var x1 = parseInt(_l[2]);
var y1 = parseInt(_l[3]);
var n = parseInt(readline());

var path = [];
var m = {};
for(var i=0; i<n; i++){
	_l = readline().split(' ').map(toInt);
	var x=_l[0];
	for(var y=_l[1]; y<=_l[2]; y++){
		path[i]=[x,y];
		m[''+x+'-'+y] = true;
	}
}

var q = [];
q.push([x0, y0]);
var _i=0;
var x = [-1,-1,-1, 1, 1, 1, 0, 0];
var y = [-1, 0, 1,-1, 0, 1,-1, 1];
out: for(var step=1; step<=1E5; step++){
	for(var l=q.length; _i<l; _i++){
		var now = q[_i];
		for(var i=0; i<8; i++){
			var xx = now[0]+x[i];
			var yy = now[1]+y[i];
			if(xx==x1&&yy==y1){
				print(step);
				break out;
			}
			if( m[''+xx+'-'+yy ] ){
				m[''+xx+'-'+yy ]=false;
				q.push([xx, yy]);
			}
		}
	}
}
if(step>1E5){
	print(-1)
}


#include<bits/stdc++.h>
using namespace std;
map<int,pair<int,int> >valid;
map<pair<int,int>,int>visited;
map<pair<int,int>,int>level;
int bfs(int x0,int y0,int x1,int y1)
{
	queue<pair<int,int> >q;
	q.push(make_pair(x0,y0));
	visited[make_pair(x0,y0)]=1;
	level[make_pair(x0,y0)]=0;
	level[make_pair(x1,y1)]=-1;
	while(!q.empty())
	{
		int ux=q.front().first;
		int uy=q.front().second;
		int l=level[make_pair(ux,uy)];
		q.pop();
		int dx[8]={-1,-1,-1,1,1,1,0,0};
		int dy[8]={0,-1,1,0,-1,1,1,-1};
		for(int i=0;i<8;i++)
		{
			int x=ux+dx[i];
			int y=uy+dy[i];
			if(valid.find(x)==valid.end())
				continue;
			int a=valid[x].first;
			int b=valid[x].second;
			if(y<a||y>b)
				continue;
			if(visited.find(make_pair(x,y))==visited.end())
			{
				visited[make_pair(x,y)]=1;
				level[make_pair(x,y)]=l+1;
				q.push(make_pair(x,y));
			}
		}
	}
	return level[make_pair(x1,y1)];
}
int main()
{
	int x0,y0,x1,y1;
	scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int r,a,b;
		scanf("%d%d%d",&r,&a,&b);
		if(valid.find(r)==valid.end())
		{
			valid[r]=make_pair(a,b);
		}
		else
		{
			int preva=valid[r].first;
			int prevb=valid[r].second;
			preva=min(preva,a);
			prevb=max(prevb,b);
			valid[r]=make_pair(preva,prevb);
		}
	}
	printf("%d\n",bfs(x0,y0,x1,y1) );
	return 0;
}


	#include<bits/stdc++.h>
	using namespace std;
	map<pair<int,int>,int>valid;
	map<pair<int,int>,int>visited;
	map<pair<int,int>,int>level;
	int bfs(int x0,int y0,int x1,int y1)
	{
		queue<pair<int,int> >q;
		q.push(make_pair(x0,y0));
		visited[make_pair(x0,y0)]=1;
		level[make_pair(x0,y0)]=0;
		level[make_pair(x1,y1)]=-1;
		while(!q.empty())
		{
			int ux=q.front().first;
			int uy=q.front().second;
			int l=level[make_pair(ux,uy)];
			q.pop();
			int dx[9]={-1,-1,-1,1,1,1,0,0};
			int dy[9]={0,-1,1,0,-1,1,1,-1};
			for(int i=0;i<8;i++)
			{
				int x=ux+dx[i];
				int y=uy+dy[i];
				if(valid.find(make_pair(x,y))==valid.end())
					continue;
				if(visited.find(make_pair(x,y))==visited.end())
				{
					visited[make_pair(x,y)]=1;
					level[make_pair(x,y)]=l+1;
					q.push(make_pair(x,y));
				}
			}
		}
		return level[make_pair(x1,y1)];
	}
	int main()
	{
		int x0,y0,x1,y1;
		scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			int r,a,b;
			scanf("%d%d%d",&r,&a,&b);
			for(int j=a;j<=b;j++)
				valid[make_pair(r,j)]=1;
		}
		printf("%d\n",bfs(x0,y0,x1,y1) );
		return 0;
	}


	#include<bits/stdc++.h>
	using namespace std;
	map<int,pair<int,int> >valid;
	map<pair<int,int>,int>visited;
	map<pair<int,int>,int>level;
	int bfs(int x0,int y0,int x1,int y1)
	{
		queue<pair<int,int> >q;
		q.push(make_pair(x0,y0));
		visited[make_pair(x0,y0)]=1;
		level[make_pair(x0,y0)]=0;
		level[make_pair(x1,y1)]=-1;
		while(!q.empty())
		{
			int ux=q.front().first;
			int uy=q.front().second;
			int l=level[make_pair(ux,uy)];
			q.pop();
			int dx[9]={-1,-1,-1,1,1,1,0,0};
			int dy[9]={0,-1,1,0,-1,1,1,-1};
			for(int i=0;i<9;i++)
			{
				int x=ux+dx[i];
				int y=uy+dy[i];
				if(valid.find(x)==valid.end())
					continue;
				int a=valid[x].first;
				int b=valid[x].second;
				if(y<a||y>b)
					continue;
				if(visited.find(make_pair(x,y))==visited.end())
				{
					visited[make_pair(x,y)]=1;
					level[make_pair(x,y)]=l+1;
					q.push(make_pair(x,y));
				}
			}
		}
		return level[make_pair(x1,y1)];
	}
	int main()
	{
		int x0,y0,x1,y1;
		scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			int r,a,b;
			scanf("%d%d%d",&r,&a,&b);
			if(valid.find(r)==valid.end())
			{
				valid[r]=make_pair(a,b);
			}
			else
			{
				int preva=valid[r].first;
				int prevb=valid[r].second;
				preva=min(preva,a);
				prevb=max(prevb,b);
				valid[r]=make_pair(preva,prevb);
			}
		}
		printf("%d\n",bfs(x0,y0,x1,y1) );
		return 0;
	}


#include<bits/stdc++.h>
using namespace std;
map<int,pair<int,int> >valid;
map<pair<int,int>,int>visited;
map<pair<int,int>,int>level;
int bfs(int x0,int y0,int x1,int y1)
{
	queue<pair<int,int> >q;
	q.push(make_pair(x0,y0));
	visited[make_pair(x0,y0)]=1;
	level[make_pair(x0,y0)]=0;
	while(!q.empty())
	{
		int ux=q.front().first;
		int uy=q.front().second;
		int l=level[make_pair(ux,uy)];
		q.pop();
		int dx[8]={-1,-1,-1,1,1,1,0,0};
		int dy[8]={0,-1,1,0,-1,1,1,-1};
		for(int i=0;i<8;i++)
		{
			int x=ux+dx[i];
			int y=uy+dy[i];
			if(valid.find(x)==valid.end())
				continue;
			int a=valid[x].first;
			int b=valid[x].second;
			if(y<a||y>b)
				continue;
			if(visited[make_pair(x,y)]==0)
			{
				visited[make_pair(x,y)]=1;
				level[make_pair(x,y)]=l+1;
				q.push(make_pair(x,y));
				if(x==x1&&y==y1)
					return l+1;
			}
		}
	}
	return -1;
}
int main()
{
	int x0,y0,x1,y1;
	scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int r,a,b;
		scanf("%d%d%d",&r,&a,&b);
		if(valid.find(r)==valid.end())
		{
			valid[r]=make_pair(a,b);
		}
		else
		{
			int preva=valid[r].first;
			int prevb=valid[r].second;
			preva=min(preva,a);
			prevb=max(prevb,b);
			valid[r]=make_pair(preva,prevb);
		}
	}
	printf("%d\n",bfs(x0,y0,x1,y1) );
	return 0;
}


#include "cstdio"
#include "iostream"
#include "cstdlib"
#include "map"
#include "vector"
#include "cstring"
#include "algorithm"
#include "queue"
using namespace std;

#define mp make_pair
typedef pair<int, int> pii;

map<pii, int> f;
deque<pii> q;
pii p0, p1;
int n;
const int ci[] = {-1, -1, -1, 1, 1, 1, 0, 0};
const int cj[] = {1, 0, -1, 1, 0, -1, 1, -1};

int main() {
    scanf("%d%d%d%d", &p0.first, &p0.second, &p1.first, &p1.second);
    scanf("%d",&n);
    for(; n; n--) {
        int r, a, b;
        scanf("%d%d%d", &r, &a, &b);
        for(int i = a; i <= b; i++) f[mp(r, i)] = -1;
    }
    if (!f[p0]) printf("-1\n");
    else {
        q.push_back(p0);
        f[p0] = 1;
        while (!q.empty()) {
            pii t = q.front(); q.pop_front();
            for(int i = 0; i < 8; i++) {
                pii tt = mp(t.first+ci[i], t.second+cj[i]);
                if (!f[tt]) continue;
                if (tt == p1) {
                    printf("%d\n", f[t]);
                    return 0;
                }
                if (f[tt] == -1) {
                    f[tt] = f[t]+1;
                    q.push_back(tt);
                }
            }
        }
        printf("-1\n");
    }
    return 0;
}


uses math;
const
  fi='';
  fo='';
  maxn = trunc(1e5);
  dx:array[1..8] of longint = (-1,-1,-1,1,1,1,0,0);
  dy:array[1..8] of longint = (-1,0,1,-1,0,1,-1,1);
  oo = trunc(1e9);
type
  point = record
    x,y:longint;
    end;
  seg = record
    r,c1,c2:longint;
    end;
  pnode = ^node;
  node = record
    x:longint;
    next:pnode;
    end;
var
  n:longint;
  s,t:point;
  ss,tt:longint;
  a:array[1..maxn] of seg;
  m:longint;
  b:array[1..maxn] of point;
  c:array[1..maxn] of pnode;
  vi:array[1..maxn] of boolean;
  d:array[1..maxn] of longint;
  qu:array[1..maxn] of longint;
  lo,hi:longint;
procedure openfile;
begin
  assign(input,fi);reset(input);
  assign(output,fo);rewrite(output);
  read(s.x,s.y,t.x,t.y);
  read(n);
  for n:=1 to n do read(a[n].r,a[n].c1,a[n].c2);
end;
procedure swap1(var s1,s2:seg);
var
  t:seg;
begin
  t:=s1;s1:=s2;s2:=t;
end;
procedure sort(l,h:longint);
var
  i,j:longint;
  t:seg;
begin
  if l>=h then exit;
  i:=l;j:=h;
  t:=a[l+random(h-l+1)];
  repeat
    while (a[i].r<t.r)or((a[i].r=t.r)and(a[i].c1<t.c1)) do inc(i);
    while (t.r<a[j].r)or((t.r=a[j].r)and(t.c1<a[j].c1)) do dec(j);
    if i<=j then
      begin
        if i<j then swap1(a[i],a[j]);
        inc(i);dec(j);
      end;
  until i>j;
  sort(l,j);sort(i,h);
end;
procedure swap2(var p1,p2:point);
var
  t:point;
begin
  t:=p1;p1:=p2;p2:=t;
end;
procedure sortp(l,h:longint);
var
  i,j:longint;
  t:point;
begin
  if l>=h then exit;
  i:=l;j:=h;
  t:=b[l+random(h-l+1)];
  repeat
    while (b[i].x<t.x)or((b[i].x=t.x)and(b[i].y<t.y)) do inc(i);
    while (t.x<b[j].x)or((t.x=b[j].x)and(t.y<b[j].y)) do dec(j);
    if i<=j then
      begin
        if i<j then swap2(b[i],b[j]);
        inc(i);dec(j);
      end;
  until i>j;
  sortp(l,j);sortp(i,h);
end;
function inner(x,y:longint):boolean;  inline;
begin
  exit((x>=1)and(x<=oo)and(y>=1)and(y<=oo));
end;
function bins(x,y:longint):longint;
var
  l,h,mid:longint;
begin
  l:=1;h:=m;
  while l<=h do
    begin
      mid:=(l+h) shr 1;
      if (b[mid].x=x)and(b[mid].y=y) then exit(mid);
      if (x<b[mid].x)or((x=b[mid].x)and(y<b[mid].y)) then h:=mid-1 else l:=mid+1;
    end;
  exit(0);
end;
procedure push(x:longint;var nod:pnode);  inline;
var
  p:pnode;
begin
  new(p);
  p^.x:=x;p^.next:=nod;
  nod:=p;
end;
procedure init;
var
  i,j,k:longint;
  l,r:longint;
begin
  sort(1,n);
  i:=0;
  m:=0;
  while i<n do
    begin
      inc(i);j:=i;
      l:=a[i].c1;
      r:=a[i].c2;
      while (j+1<=n)and(a[j+1].r=a[j].r) do
        begin
          inc(j);
          if a[j].c1>r then
            begin
              for k:=l to r do
                begin
                  inc(m);
                  b[m].x:=a[i].r;b[m].y:=k;
                  l:=a[j].c1;
                  r:=a[j].c2;
                end;
            end
          else
            begin
              r:=max(r,a[j].c2);
            end;
        end;
      for k:=l to r do
        begin
          inc(m);
          b[m].x:=a[i].r;b[m].y:=k;
        end;
      i:=j;
    end;
  sortp(1,m);
  fillchar(c,sizeof(c),0);
  for i:=1 to m do
    for j:=1 to 8 do
      if inner(b[i].x+dx[j],b[i].y+dy[j]) then
        begin
          k:=bins(b[i].x+dx[j],b[i].y+dy[j]);
          if k>0 then
            begin
              push(k,c[i]);
              push(i,c[k]);
            end;
        end;
end;
procedure process;
var
  u:longint;
  p:pnode;
begin
  init;
  ss:=bins(s.x,s.y);
  tt:=bins(t.x,t.y);
  if (ss=0)or(tt=0) then
    begin
      writeln(-1);exit;
    end;
  lo:=1;hi:=1;
  qu[1]:=ss;
  fillchar(vi,sizeof(vi),0);
  fillchar(d,sizeof(d),0);
  vi[ss]:=true;
  d[ss]:=0;
  while lo<=hi do
    begin
      u:=qu[lo];inc(lo);
      p:=c[u];
      if u=tt then
        begin
          writeln(d[tt]);
          exit;
        end;
      while p<>nil do
        begin
          if not vi[p^.x] then
            begin
              vi[p^.x]:=true;
              d[p^.x]:=d[u]+1;
              inc(hi);qu[hi]:=p^.x;
            end;
          p:=p^.next;
        end;
    end;
  writeln(-1);
end;
BEGIN
  openfile;
  process;
END.


#include "cstdio"
#include "iostream"
#include "cstdlib"
#include "map"
#include "vector"
#include "cstring"
#include "algorithm"
#include "queue"
using namespace std;

#define mp make_pair

pair<int, int> p0, p1;
vector<pair<int, int> > d[111111];
priority_queue<pair<long long, pair<int, int> > > f;
int dd[111111];
int n;
map<pair<int, int>, bool> ck;

int main() {
    // freopen("in", "r", stdin);
    scanf("%d%d", &p0.first, &p0.second);
    scanf("%d%d", &p1.first, &p1.second);
    scanf("%d", &n);
    if (p0.first > p1.first) swap(p1, p0);
    int dy = p0.first;
    p0.first = 0;
    p1.first -= dy;
    for(int i = 0; i < n; i++) {
        int r, u, v;
        scanf("%d%d%d", &r, &u, &v);
        r -= dy;
        if (r >= 0 && r <= n)
            d[r].push_back(make_pair(u, v));
    }
    memset(dd, 0, sizeof dd);
    for(int i = 0; i <= n; i++) {
        sort(d[i].begin(), d[i].end());
        int prev, j;
        for(prev = 0, j = 1; j < d[i].size(); j++)
            if (d[i][j].first <= d[i][prev].second+1)
                d[i][prev].second = d[i][j].second;
            else d[i][++prev] = d[i][j];
        while (prev+1 < d[i].size()) d[i].pop_back();
    }
    f.push(mp(0, p0));
    while (!f.empty()) {
        pair<long long, pair<int, int> > t = f.top(); f.pop();
        int x = t.second.second;
        int y = t.second.first;
        if (ck[mp(x, y)]) continue;
        ck[mp(x, y)] = true;
        // cout << y << " " << x << " " << t.first << endl;
        if (t.second == p1) {
            cout << -t.first;
            return 0;
        }
        int l = 0, r = d[y].size()-1;
        if (y < 0 || y >= n) continue;
        while (l < r) {
            int mid = (l+r)/2;
            if (d[y][mid].second < x) l = mid+1;
            else r = mid;
        }

        if (l < d[y].size() && d[y][l].first <= x && x <= d[y][l].second) {
            // cout << l << endl;
            if (y > 0) {
                f.push(mp(t.first-1, mp(y-1, x-1)));
                f.push(mp(t.first-1, mp(y-1, x)));
                f.push(mp(t.first-1, mp(y-1, x+1)));
            }

            if (y < n) {
                f.push(mp(t.first-1, mp(y+1, x-1)));
                f.push(mp(t.first-1, mp(y+1, x)));
                f.push(mp(t.first-1, mp(y+1, x+1)));
            }
            f.push(mp(t.first-1, mp(y, x+1)));
            f.push(mp(t.first-1, mp(y, x-1)));
            f.push(mp(t.first-x+d[y][l].first, mp(y, d[y][l].first)));
            f.push(mp(t.first-d[y][l].second+x, mp(y, d[y][l].second)));
            if (p1.second == y && d[y][l].second >= p1.first && d[y][l].first <= p1.first)
                f.push(mp(t.first-abs(p1.first-x), p1));
        }
    }
    cout << -1;
    return 0;
}


#include "cstdio"
#include "iostream"
#include "cstdlib"
#include "map"
#include "vector"
#include "cstring"
#include "algorithm"
#include "queue"
using namespace std;

#define mp make_pair

pair<int, int> p0, p1;
vector<pair<int, int> > d[111111];
priority_queue<pair<long long, pair<int, int> > > f;
int dd[111111];
int n;
map<pair<int, int>, bool> ck;

int main() {
    // freopen("in", "r", stdin);
    scanf("%d%d", &p0.first, &p0.second);
    scanf("%d%d", &p1.first, &p1.second);
    scanf("%d", &n);
    if (p0.first > p1.first) swap(p1, p0);
    int dy = p0.first;
    p0.first = 0;
    p1.first -= dy;
    for(int i = 0; i < n; i++) {
        int r, u, v;
        scanf("%d%d%d", &r, &u, &v);
        r -= dy;
        if (r >= 0 && r <= n)
            d[r].push_back(make_pair(u, v));
    }
    memset(dd, 0, sizeof dd);
    for(int i = 0; i <= n; i++) {
        sort(d[i].begin(), d[i].end());
        int prev, j;
        for(prev = 0, j = 1; j < d[i].size(); j++)
            if (d[i][j].first <= d[i][prev].second)
                d[i][prev].second = d[i][j].second;
            else d[i][++prev] = d[i][j];
        while (prev+1 < d[i].size()) d[i].pop_back();
    }
    f.push(mp(0, p0));
    while (!f.empty()) {
        pair<long long, pair<int, int> > t = f.top(); f.pop();
        int x = t.second.second;
        int y = t.second.first;
        if (ck[mp(x, y)]) continue;
        ck[mp(x, y)] = true;
        // cout << y << " " << x << " " << t.first << endl;
        if (t.second == p1) {
            cout << -t.first;
            return 0;
        }
        int l = 0, r = d[y].size()-1;
        if (y < 0 || y >= n) continue;
        while (l < r) {
            int mid = (l+r)/2;
            if (d[y][mid].second < x) l = mid+1;
            else r = mid;
        }

        if (l < d[y].size() && d[y][l].first <= x && x <= d[y][l].second) {
            // cout << l << endl;
            if (y > 0) {
                f.push(mp(t.first-1, mp(y-1, x-1)));
                f.push(mp(t.first-1, mp(y-1, x)));
                f.push(mp(t.first-1, mp(y-1, x+1)));
            }

            if (y < n) {
                f.push(mp(t.first-1, mp(y+1, x-1)));
                f.push(mp(t.first-1, mp(y+1, x)));
                f.push(mp(t.first-1, mp(y+1, x+1)));
            }

            f.push(mp(t.first-1, mp(y, x+1)));
            f.push(mp(t.first-1, mp(y, x-1)));
            f.push(mp(t.first-x+d[y][l].first, mp(y, d[y][l].first)));
            f.push(mp(t.first-d[y][l].second+x, mp(y, d[y][l].second)));
            if (p1.second == y && d[y][l].second >= p1.first && d[y][l].first <= p1.first)
                f.push(mp(t.first-abs(p1.first-x), p1));
        }
    }
    cout << -1;
    return 0;
}


    #include "cstdio"
    #include "iostream"
    #include "cstdlib"
    #include "map"
    #include "vector"
    #include "cstring"
    #include "algorithm"
    #include "queue"
    using namespace std;

    #define mp make_pair

    pair<int, int> p0, p1;
    vector<pair<int, int> > d[111111];
    priority_queue<pair<long long, pair<int, int> > > f;
    int n;
    map<pair<int, int>, bool> ck;

    int main() {
        // freopen("in", "r", stdin);
        scanf("%d%d", &p0.first, &p0.second);
        scanf("%d%d", &p1.first, &p1.second);
        scanf("%d", &n);
        if (p0.first > p1.first) swap(p1, p0);
        int dy = p0.first;
        p0.first = 0;
        p1.first -= dy;
        for(int i = 0; i < n; i++) {
            int r, u, v;
            scanf("%d%d%d", &r, &u, &v);
            r -= dy;
            if (r >= 0 && r <= n)
                d[r].push_back(make_pair(u, v));
        }
        for(int i = 0; i <= n; i++) {
            sort(d[i].begin(), d[i].end());
            int prev, j;
            for(prev = 0, j = 1; j < d[i].size(); j++)
                if (d[i][j].first <= d[i][prev].second+1)
                    d[i][prev].second = d[i][j].second;
                else d[i][++prev] = d[i][j];
            while (prev+1 < d[i].size()) d[i].pop_back();
        }
        f.push(mp(0, p0));
        while (!f.empty()) {
            pair<long long, pair<int, int> > t = f.top(); f.pop();
            int x = t.second.second;
            int y = t.second.first;
            if (ck[mp(x, y)]) continue;
            ck[mp(x, y)] = true;
            // cout << y << " " << x << " " << t.first << endl;
            int l = 0, r = d[y].size()-1;
            if (y < 0 || y >= n) continue;
            while (l < r) {
                int mid = (l+r)/2;
                if (d[y][mid].second < x) l = mid+1;
                else r = mid;
            }

            if (l < d[y].size() && d[y][l].first <= x && x <= d[y][l].second) {
                    if (t.second == p1) {
                    cout << -t.first;
                    return 0;
                }
                // cout << l << endl;
                if (y > 0) {
                    f.push(mp(t.first-1, mp(y-1, x-1)));
                    f.push(mp(t.first-1, mp(y-1, x)));
                    f.push(mp(t.first-1, mp(y-1, x+1)));
                }

                if (y < n) {
                    f.push(mp(t.first-1, mp(y+1, x-1)));
                    f.push(mp(t.first-1, mp(y+1, x)));
                    f.push(mp(t.first-1, mp(y+1, x+1)));
                }
                f.push(mp(t.first-1, mp(y, x+1)));
                f.push(mp(t.first-1, mp(y, x-1)));
                f.push(mp(t.first-x+d[y][l].first, mp(y, d[y][l].first)));
                f.push(mp(t.first-d[y][l].second+x, mp(y, d[y][l].second)));
                if (p1.second == y && d[y][l].second >= p1.first && d[y][l].first <= p1.first)
                    f.push(mp(t.first-abs(p1.first-x), p1));
            }
        }
        cout << -1;
        return 0;
    }


#include "cstdio"
#include "iostream"
#include "cstdlib"
#include "map"
#include "vector"
#include "cstring"
#include "algorithm"
#include "queue"
using namespace std;

#define mp make_pair

pair<int, int> p0, p1;
vector<pair<int, int> > d[111111];
priority_queue<pair<long long, pair<int, int> > > f;
int dd[111111];
int n;
map<pair<int, int>, bool> ck;

int main() {
    // freopen("in", "r", stdin);
    scanf("%d%d", &p0.first, &p0.second);
    scanf("%d%d", &p1.first, &p1.second);
    scanf("%d", &n);
    if (p0.first > p1.first) swap(p1, p0);
    int dy = p0.first;
    p0.first = 0;
    p1.first -= dy;
    for(int i = 0; i < n; i++) {
        int r, u, v;
        scanf("%d%d%d", &r, &u, &v);
        r -= dy;
        if (r >= 0 && r <= n)
            d[r].push_back(make_pair(u, v));
    }
    memset(dd, 0, sizeof dd);
    for(int i = 0; i <= n; i++) {
        sort(d[i].begin(), d[i].end());
        int prev, j;
        for(prev = 0, j = 1; j < d[i].size(); j++)
            if (d[i][j].first <= d[i][prev].second)
                d[i][prev].second = d[i][j].second;
            else d[i][++prev] = d[i][j];
        while (prev+1 < d[i].size()) d[i].pop_back();
    }
    f.push(mp(0, p0));
    int ret = 0;
    while (!f.empty()) {
        pair<long long, pair<int, int> > t = f.top(); f.pop();
        int x = t.second.second;
        int y = t.second.first;
        if (ck[mp(x, y)]) continue;
        ck[mp(x, y)] = true;
        // cout << y << " " << x << " " << t.first << endl;
        if (t.second == p1) {
            cout << -t.first;
            return 0;
        }
        int l = 0, r = d[y].size()-1;
        if (y < 0 || y >= n) continue;
        while (l < r) {
            int mid = (l+r)/2;
            if (d[y][mid].second < x) l = mid+1;
            else r = mid;
        }

        if (l < d[y].size() && d[y][l].first <= x && x <= d[y][l].second) {
            // cout << l << endl;
            if (y > 0) {
                f.push(mp(t.first-1, mp(y-1, x-1)));
                f.push(mp(t.first-1, mp(y-1, x)));
                f.push(mp(t.first-1, mp(y-1, x+1)));
            }

            if (y < n) {
                f.push(mp(t.first-1, mp(y+1, x-1)));
                f.push(mp(t.first-1, mp(y+1, x)));
                f.push(mp(t.first-1, mp(y+1, x+1)));
            }

            f.push(mp(t.first-1, mp(y, x+1)));
            f.push(mp(t.first-1, mp(y, x-1)));
            f.push(mp(t.first-x+d[y][l].first, mp(y, d[y][l].first)));
            f.push(mp(t.first-d[y][l].second+x, mp(y, d[y][l].second)));
            if (p1.second == y && d[y][l].second >= p1.first && d[y][l].first <= p1.first) {
                f.push(mp(t.first-abs(p1.first-x), mp(y, d[y][l].second)));
            }
        }
    }
    cout << -1;
    return 0;
}


#include <cstdio>
#include <map>
#include <utility>
#define mp make_pair
#define X first
#define Y second
using namespace std;

map< pair<int,int>,bool > a,b;
const int d[8][2]={{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,1},{-1,0},{-1,1}};
int n,x0,y0,x1,y1,dst[100100];
pair<int,int> lin[100100];

int main() {
	scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
	scanf("%d",&n);
	for (int i=1;i<=n;++i) {
		int k,l,r;
		scanf("%d%d%d",&k,&l,&r);
		for (int j=l;j<=r;++j) a[mp(k,j)]=true;
	}
	int l=1,r=1;
	lin[1]=mp(x0,y0);
	b[mp(x0,y0)]=true;
	for (;l<=r;++l)
		for (int i=0;i<8;++i) {
			int x=lin[l].X+d[i][0];
			int y=lin[l].Y+d[i][1];
			if ((x==x1)&&(y==y1)) {printf("%d\n",dst[l]+1);return 0;}
			if ((a[mp(x,y)])&&(!b[mp(x,y)]))
				b[mp(x,y)]=true,lin[++r]=mp(x,y),dst[r]=dst[l]+1;
		}
	printf("-1\n");
	return 0;
}


#include <cstdio>
#include <map>
#include <utility>
#define mp make_pair
#define X first
#define Y second
using namespace std;

map< pair<int,int>,bool > a,b;
int n,x0,y0,x1,y1,dst[100100];
pair<int,int> lin[100100];

int main() {
	scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
	scanf("%d",&n);
	for (int i=1;i<=n;++i) {
		int k,l,r;
		scanf("%d%d%d",&k,&l,&r);
		for (int j=l;j<=r;++j) a[mp(k,j)]=true;
	}
	int l=1,r=1;
	lin[1]=mp(x0,y0);
	b[mp(x0,y0)]=true;
	for (;l<=r;++l)
		for (int dx=-1;dx<=1;++dx)
			for (int dy=-1;dy<=1;++dy) {
				int x=lin[l].X+dx;
				int y=lin[l].Y+dy;
				if ((x<1)||(y<1)||(x>1000000000)||(y>1000000000)) continue;
				if ((x==x1)&&(y==y1)) {printf("%d\n",dst[l]+1);return 0;}
				if ((a[mp(x,y)])&&(!b[mp(x,y)]))
					b[mp(x,y)]=true,lin[++r]=mp(x,y),dst[r]=dst[l]+1;
			}
	printf("-1\n");
	return 0;
}


#include <cstdio>
#include <map>
#include <utility>
#define mp make_pair
#define X first
#define Y second
using namespace std;

map< pair<int,int>,bool > a,b;
const int d[8][2]={{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,1},{-1,0},{-1,1}};
int n,x0,y0,x1,y1,dst[100100];
pair<int,int> lin[100100];

int main() {
	scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
	scanf("%d",&n);
	for (int i=1;i<=n;++i) {
		int k,l,r;
		scanf("%d%d%d",&k,&l,&r);
		for (int j=l;j<=r;++j) a[mp(k,j)]=true;
	}
	int l=1,r=1;
	lin[1]=mp(x0,y0);
	for (;l<=r;++l)
		for (int i=0;i<8;++i) {
			int x=lin[l].X+d[i][0];
			int y=lin[l].Y+d[i][1];
			if ((x==x1)&&(y==y1)) {printf("%d\n",dst[l]+1);return 0;}
			if ((a[mp(x,y)])&&(!b[mp(x,y)]))
				b[mp(x,y)]=true,lin[++r]=mp(x,y),dst[r]=dst[l]+1;
		}
	printf("-1\n");
	return 0;
}


/*
  Aditya Gourav
  @adi_pearl / @aditya_pearl

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

//scanning
#define si(x) scanf("%d",&x)
#define si2(x,y) scanf("%d%d",&x,&y)
#define si3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define si4(x,y,z,a) scanf("%d%d%d%d",&x,&y,&z,&a)
#define ss(x) scanf("%s",x)
#define sd(x) scanf("%lf",&x)
//debugging
#define db1(msg,x) printf("%s: %d\n",msg,x)
#define db2(msg,x,y) printf("%s: %d %d\n",msg,x,y)
#define db3(msg,x,y,z) printf("%s: %d %d %d\n",msg,x,y,z)
#define db(msg) printf("%s\n",msg)
//printing to console
#define pi(x) printf("%d\n",x)
#define pi2(x,y) printf("%d %d\n",x,y)
#define pill(x) printf("%lld\n",x)
#define pd(x) printf("%lf\n",x)
//others
#define ForInc(var,beg,end) for(int var=beg;var<=end;++var)
#define advForInc(var,beg,end,inc) for(int var=beg;var<=end;var+=inc)
#define ForDec(var,end,beg) for(int var=end;var>=beg;--var)
#define ipArray(arr,size) ForInc(i,0,size-1) si(arr[i]);
#define ipllArray(arr,size) ForInc(i,0,size-1) sill(arr[i]);
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define READ(f) freopen(f,"r",stdin);
#define WRITE(f) freopen(f,"w",stdout);
#define TEST int testcases; cin>>testcases;for(;testcases;--testcases)

template<typename T> T gcd(T a, T b) { return (b == 0) ? abs(a) : gcd(b, a % b); }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> inline T mod(T a, T b) { return (a % b + b) % b; }
template<typename T> inline T sqr(T x) { return ((x) * (x)); }

const double EPS = 1e-9;
const double BIG = 1e19;
const int INF = INT_MAX;

typedef long long ll;

/* Main Code starts here :) */
ii src,dest;
int dz[][2]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,1},{1,-1},{-1,-1}};
int n;
struct row_t{
    int s,e;
    row_t(){}
    row_t(int a, int b){s=a;e=b;}
};
set<ii> valid,visited;
#define x first
#define y second
#define MAX 1000000000
#define bn pair<ii,int>
struct node{
    int x,y;int dist;
    node(){}
    node(int r, int c, int d):x(r),y(c),dist(d){}
};
void bfs(){
    int ans=-1;
    queue<node> q;
    q.push(node(src.x,src.y,0));visited.insert(src);
    while(!q.empty()){
        node u=q.front();q.pop();
        if(u.x==dest.x&&u.y==dest.y){ans=u.dist;break;}
        ForInc(k,0,7){
            ii v;v.x=u.x+dz[k][0];v.y=u.y+dz[k][1];
            if(valid.find(v)!=valid.end() && visited.find(v)==visited.end()){
                q.push(node(v.x,v.y,u.dist+1));
                visited.insert(v);
            }
        }
    }
    pi(ans);
}
int main(){
    int a,b,r;
    si4(src.x,src.y,dest.x,dest.y);
    si(n);
    ForInc(i,1,n){
        si3(r,a,b);
        ForInc(j,a,b)valid.insert(ii(r,j));
    }
    bfs();
return 0;
}


/*
  Aditya Gourav
  @adi_pearl / @aditya_pearl

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

//scanning
#define si(x) scanf("%d",&x)
#define si2(x,y) scanf("%d%d",&x,&y)
#define si3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define si4(x,y,z,a) scanf("%d%d%d%d",&x,&y,&z,&a)
#define ss(x) scanf("%s",x)
#define sd(x) scanf("%lf",&x)
//debugging
#define db1(msg,x) printf("%s: %d\n",msg,x)
#define db2(msg,x,y) printf("%s: %d %d\n",msg,x,y)
#define db3(msg,x,y,z) printf("%s: %d %d %d\n",msg,x,y,z)
#define db(msg) printf("%s\n",msg)
//printing to console
#define pi(x) printf("%d\n",x)
#define pi2(x,y) printf("%d %d\n",x,y)
#define pill(x) printf("%lld\n",x)
#define pd(x) printf("%lf\n",x)
//others
#define ForInc(var,beg,end) for(int var=beg;var<=end;++var)
#define advForInc(var,beg,end,inc) for(int var=beg;var<=end;var+=inc)
#define ForDec(var,end,beg) for(int var=end;var>=beg;--var)
#define ipArray(arr,size) ForInc(i,0,size-1) si(arr[i]);
#define ipllArray(arr,size) ForInc(i,0,size-1) sill(arr[i]);
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define READ(f) freopen(f,"r",stdin);
#define WRITE(f) freopen(f,"w",stdout);
#define TEST int testcases; cin>>testcases;for(;testcases;--testcases)

template<typename T> T gcd(T a, T b) { return (b == 0) ? abs(a) : gcd(b, a % b); }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> inline T mod(T a, T b) { return (a % b + b) % b; }
template<typename T> inline T sqr(T x) { return ((x) * (x)); }

const double EPS = 1e-9;
const double BIG = 1e19;
const int INF = INT_MAX;

typedef long long ll;

/* Main Code starts here :) */
ii src,dest;
int dz[][2]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,1},{1,-1},{-1,-1}};
int n;
struct row_t{
    int s,e;
    row_t(){}
    row_t(int a, int b){s=a;e=b;}
};
map<int,row_t> row;
map<ii,int> d;
map<ii,bool> visited;
map<ii,bool> inQ;
#define x first
#define y second
#define MAX 1000000000
void bfs(){
    queue<ii> q;
    q.push(src);d[src]=0;
    while(!q.empty()){
        ii u=q.front();q.pop();
        visited[u]=1;
        ForInc(k,0,7){
            ii v;v.x=u.x+dz[k][0];v.y=u.y+dz[k][1];
            if(v.x<1||v.x>MAX||v.y<1||v.y>MAX||
               (row.find(v.x)==row.end()||(v.y<row[v.x].s||v.y>row[v.x].e)))continue;
            if(visited.find(v)==visited.end() && inQ.find(v)==inQ.end()){
                q.push(v);inQ[v]=1;
            }
            if(d.find(v)==d.end())d[v]=d[u]+1;else d[v]=min(d[v],d[u]+1);
        }
    }
    if(d.find(dest)==d.end())printf("-1\n");
    else pi(d[dest]);
}
int main(){
    int a,b,r;
    si4(src.x,src.y,dest.x,dest.y);
    si(n);
    ForInc(i,1,n){
        si3(r,a,b);row[r]=row_t(a,b);
    }
    bfs();
return 0;
}