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

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

b = A("b")
f = B("f")
i = A("i")
l = B("l")
d = B("d")
j = B("j")
g = B("g")
n = A("n")

b.s = n
f.r = b
f.p = j
i.s = n
l.r = i
l.p = d
d.r = i
d.p = f
j.r = b
j.p = g
g.r = i
g.p = l
n.s = b
assert i.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

b = A("b")
f = B("f")
i = A("i")
l = B("l")
d = B("d")
j = B("j")
g = B("g")
n = A("n")

b.s = n
f.r = b
f.p = j
i.s = n
l.r = i
l.p = d
d.r = i
d.p = f
j.r = b
j.p = g
g.r = i
g.p = l
n.s = b
assert i.s.s.s.s.s.s.s.txt == "n"