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

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

k = A("k")
j = B("j")
m = A("m")
n = B("n")
g = B("g")
i = B("i")
b = B("b")

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

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

k = A("k")
j = B("j")
m = A("m")
n = B("n")
g = B("g")
i = B("i")
b = B("b")

k.p = m
k.w = m
j.s = b
m.p = k
m.w = k
n.s = i
g.s = b
i.s = j
b.s = n
assert j.s.s.s.s.s.s.s.txt == "i"