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

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

m = A("m")
n = B("n")
i = A("i")
d = A("d")
j = B("j")

m.s = j
n.p = d
i.s = n
d.s = j
j.p = i
assert n.p.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

m = A("m")
n = B("n")
i = A("i")
d = A("d")
j = B("j")

m.s = j
n.p = d
i.s = n
d.s = j
j.p = i
assert n.p.s.p.s.txt == "n"