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

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

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

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

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

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

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