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

public class wall_ek {
    private class WallRecipe {
        public WallRecipe() {
            this.successful = false;
            this.height = 0;
            this.actions = null;
        }

        public WallRecipe(int height, Action[] actions) {
            this.successful = true;
            this.height = height;
            this.actions = actions;
        }

        public void print(PrintWriter out) {
            out.print(height);
            out.print(" ");
            out.println(actions.length);
            for (int i = 0; i < actions.length; ++i) {
                out.print(actions[i].i + 1);
                out.print(" ");
                out.println(actions[i].j + 1);
            }
        }

        public boolean isSuccessful() {
            return successful;
        }

        private final boolean successful;
        private final int height;
        private final Action[] actions;
    }

    private class Action {
        public Action(int i, int j) {
            this.i = i;
            this.j = j;
        }

        public final int i;
        public final int j;
    }

    private class WallRecipeCreator {
        public WallRecipeCreator() {
            height = Integer.MAX_VALUE;
            actions = new ArrayList<>();
        }

        public WallRecipe create() {
            return new WallRecipe(height, actions.toArray(new Action[0]));
        }

        public WallRecipe createUnsuccessful() {
            return new WallRecipe();
        }

        public void addSimple(int curHeight) {
            if (this.height > curHeight) {
                this.height = curHeight;
            }
        }

        public void addComplex(int curHeight, int i, int j) {
            if (this.height > curHeight) {
                this.height = curHeight;
            }
            actions.add(new Action(i, j));
        }

        private int height;
        private ArrayList <Action> actions;
    }

    WallRecipe tryBuildWall(int n, int[] a, int m, int[] b, int minH) {
        WallRecipeCreator creator = new WallRecipeCreator();
        for (int i = 0, j = 0; i < n; ++i) {
            if (a[i] >= minH) {
                creator.addSimple(a[i]);
                continue;
            }
            while (j < m && a[i] + b[j] < minH) {
                ++j;
            }
            if (j == m) {
                return creator.createUnsuccessful();
            }
            creator.addComplex(a[i] + b[j], i, j);
            ++j;
        }
        return creator.create();
    }

    private void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = nextInt();
        }
        int m = nextInt();
        int[] b = new int[m];
        for (int i = 0; i < m; ++i) {
            b[i] = nextInt();
        }

        int L = 1;
        int R = (int)2e9 + 1;
        while (L + 1 < R) {
            int M = L + (R - L) / 2;
            WallRecipe result = tryBuildWall(n, a, m, b, M);
            if (result.isSuccessful()) {
                L = M;
            } else {
                R = M;
            }
        }
        WallRecipe result = tryBuildWall(n, a, m, b, L);
        result.print(out);
    }
    
    public void run() throws IOException {
        br = new BufferedReader(new FileReader("wall.in"));
        out = new PrintWriter("wall.out");
        solve();
        out.close();
        br.close();
    }

    public static void main(String[] args) throws IOException {
        new wall_ek().run();
    }

    BufferedReader br;
    StringTokenizer str;
    PrintWriter out;

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

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

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

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