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

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

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

j.p = n
l.s = k
i.s = k
c.s = a
a.s = c
n.p = h
d.p = b
k.s = a
b.p = j
h.p = b
assert l.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

j.p = n
l.s = k
i.s = k
c.s = a
a.s = c
n.p = h
d.p = b
k.s = a
b.p = j
h.p = b
assert l.s.s.s.s.s.s.s.txt == "c"