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

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

n = A("n")
l = B("l")
d = A("d")
f = A("f")
h = B("h")
c = A("c")
j = A("j")
i = A("i")
a = A("a")

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

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

n = A("n")
l = B("l")
d = A("d")
f = A("f")
h = B("h")
c = A("c")
j = A("j")
i = A("i")
a = A("a")

n.r = l
n.s = i
l.r = c
l.o = j
d.r = l
d.s = a
f.r = l
f.s = a
h.r = n
h.o = i
c.r = h
c.s = f
j.r = h
j.s = n
i.r = h
i.s = a
a.r = h
a.s = f
assert f.r.o.s.s.s.s.txt == "f"