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

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

n = A("n")
f = B("f")
a = B("a")
l = B("l")
i = B("i")
k = B("k")
d = B("d")
h = B("h")
g = A("g")
e = A("e")

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

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

n = A("n")
f = B("f")
a = B("a")
l = B("l")
i = B("i")
k = B("k")
d = B("d")
h = B("h")
g = A("g")
e = A("e")

n.o = d
f.r = i
a.r = h
l.r = k
i.r = k
k.r = l
d.r = i
h.r = l
g.o = f
e.o = k
assert g.o.r.r.r.r.r.r.r.r.txt == "k"