[Question]
  [
Write a program that takes as input a string and an integer `n`, and outputs:
1. The string that was passed to the program `n` times ago;
2. A new program that will be used for the next invocation.
You cannot store any data outside of the program, and your program cannot call previous programs in the chain. If the string does not exist, output an empty string (but still output the next program).
Example run, where I use the notation `program_n` for each successive program (Of course, `[This text is the nth program]` would be replaced with actual code.)
```
$ program_1 "One" 1
[This text is the second program]
$ program_2 "Two" 1
One
[This text is the third program]
$ program_3 "Three" 2
One
[This text is the fourth program]
$ program_4 "Four" 2
Two
[This text is the fifth program]
$ program_5 "Five" 1
Four
[This text is the sixth program]
```
  
[Answer]
# CJam, 25
```
L{\_l~(>1<lN+a@+`@"_~"}_~
```
[Try it online](http://cjam.aditsu.net/#code=L%7B%5C_l~(%3E1%3ClN%2Ba%40%2B%60%40%22_~%22%7D_~&input=1%0AOne)
**Explanation:**
```
L      push an empty array (this is the array of previous strings)
{…}    push this block
_      duplicate the block
~      execute the 2nd copy (the stack contains the array and the block)
```
The block:
```
\      swap the array with the block
_      duplicate the array
l      read a line from the input (containing the integer n)
~(     evaluate n and decrement it
>      slice the array starting at that position
1<     slice the resulting array to keep only the first string (if any)
l      read the 2nd line from the input (containing the string)
N+     append a newline
a      wrap in an array
@      bring the previous array to the top
+      concatenate the arrays, thus prepending the new string
`      convert the array to its string representation
@      bring the block to the top
"_~"   push this string
```
At the end, the requested string (if any), the array's representation, the block and the string "\_~" are printed automatically.
[Answer]
## Python, 221 bytes
```
import sys
o,p=[''],r'import sys;a,o,p=int(sys.argv[2]),[{2},{0}],{1};print o[a] if len(o)>a else "","\n",p.format(`sys.argv[1]`,`p`,",".join(`s`for s in o))'
print '\n',p.format(`sys.argv[1]`,`p`,','.join(`s`for s in o))
```
To test this easily, use `./thisgolf.py "yourfirststring" | python -c "import sys;exec(sys.stdin.read().split('\n')[1])" "your second string" <N>`, repeating the last bit as many times as you'd like.
[Answer]
# Python 2, 207 bytes
```
def r(O,R):import sys,marshal as m;a=sys.argv;b=int(a[2]);O.extend(["",""]*b);O[b]=a[1];print"%s\nfrom marshal import*;c=%r;i=lambda:0;i.__code__=loads(c);i(%r,i)"%(O[0],m.dumps(R.__code__),O[1:])
r([""],r)
```
Built on [my other quine but changes program](https://codegolf.stackexchange.com/questions/57171/mutant-pangolin/57232#57232), this task is simpler so I was able to golf this further. If I was able to take the input to stdin, this should be much shorter.
[Answer]
# [Python 3](https://docs.python.org/3/), 90 bytes
```
a=["a+=input(),;print(*a[1:-int(input())][-1:],'a=%r;exec(a[0])'%a,sep='\\n')"];exec(a[0])
```
[Try it online!](https://tio.run/##TU5Nb4MwDL37V1iWKkiXSmO7UeVf7AY5pMWUSDSJQli3X88Stkk9@NnS8/sI32ny7n27@oFVJKLNqI7Mi7IurKkW8hyidak@mq5pT@X6I4TuTk2rZWXUIZ75i6@16V61qA5GLhxU1feuEqSfqC3bwxj9HS@rnZN1C9p78DHhnoFmwQAw8Ij/mfG2SCxuhCSR3aCodyRawNvsL2bGUht2RIXlPZfSgOFZm@dXm0cAPCY7M37ElbPNXq7IRRGJzTuGBtLDF5wiM7zB6NdYlv3M3A8 "Python 3 – Try It Online")
## How it works:
* `a` store `[<code>, <first call>, ..., <last call>]`
* `a[1:-int(input())]` gives the sublist `[<first call>, ..., <wanted call>]` (or the empty list if the wanted call doesn't exist). Then `[-1:]` gives the singleton of the last element of that sublist if it exists (the empty list otherwise). `*` then unpack the sublist.
* The quine part is based on the quine `a="print('a=%r;exec(a)'%a)";exec(a)`
[Answer]
# Javascript ES6, ~~130~~ ~~128~~ ~~121~~ ~~120~~ 113 bytes
```
a=[];b=_=>{a.push(prompt());console.log((a[a.length-prompt()-1]||"")+`
a=`+JSON.stringify(a)+";b="+b+";b()")};b()
```
[Answer]
# [Julia 1.0](http://julialang.org/), 87 bytes
```
(a=:(a=[ARGS[1];a];print("(a=(println($a[parse(Int,ARGS[2])]);$a))[end]|>eval")))|>eval
```
[Try it online!](https://tio.run/##fVHBTgMhEL3PVxDSAyRrk91jmzXxovFgTNQbEoOFtjQENrNs68H/8gP8sBWW1qYeJAFmHu8Nb2A3OKvqj7FrUR0opSNT7SJNcfN09yxquVRy2aH1kdGEsil0ns2U6BT2ht37WE3URnLJlzPFuTBey89rs1eOcs5LNKbaANiiUdpZb3rGAbKQtERQWlEqAbRZq8HFtz7qMMR0UgKAdUBiifWkXjjjN3HLkH9/NUDSOBpNbBSNvarlGW1OaMEY6oockGfQaItmdboqmcmEbJQ9mKjmpbmOF/wv@9Jn4axcSIpUfcqK/XOzqAt@fL85@9WdXrRkdp36bFtST1keGxfelSNdKrcL1mdhReirp0fLrjf/cUWzyN9xIfEa0hwfvYEaXg4hr1s0Bhq4DQPmze7T2Q8 "Julia 1.0 – Try It Online")
smilar approach than [Jakque's answer](https://codegolf.stackexchange.com/a/231680/98541) but reversing the history order:
* `a` stores `[<last string>, ..., <first string>, <code>]`
* based on [this quine by Dennis](https://codegolf.stackexchange.com/a/92455/98541)
* the code is stored as a [`quote`](https://docs.julialang.org/en/v1/manual/metaprogramming/#Quoting), which adds some ugly formatting but is equivalent
]