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

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

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

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

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

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

j.p = c
f.s = n
g.s = n
b.s = n
m.p = b
c.s = m
n.p = b
i.s = j
d.p = i
assert i.s.p.s.p.s.p.s.p.txt == "b"