class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

k = A("k")
j = B("j")
a = B("a")
i = A("i")
c = B("c")
n = B("n")
f = B("f")
g = A("g")
e = A("e")

k.r = g
j.o = e
a.o = i
i.r = g
c.o = g
n.o = i
f.o = e
g.r = k
e.r = g
assert a.o.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

k = A("k")
j = B("j")
a = B("a")
i = A("i")
c = B("c")
n = B("n")
f = B("f")
g = A("g")
e = A("e")

k.r = g
j.o = e
a.o = i
i.r = g
c.o = g
n.o = i
f.o = e
g.r = k
e.r = g
assert a.o.r.r.r.r.r.r.txt == "k"