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

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

b = A("b")
j = B("j")
h = A("h")
k = A("k")
a = B("a")
g = B("g")
i = A("i")

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

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

b = A("b")
j = B("j")
h = A("h")
k = A("k")
a = B("a")
g = B("g")
i = A("i")

b.w = k
b.p = i
j.s = k
h.w = i
h.p = k
k.w = b
k.p = i
a.s = i
g.s = b
i.w = k
i.p = h
assert b.p.p.p.w.w.txt == "k"