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

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

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

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

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

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

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