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

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

n = A("n")
d = B("d")
i = A("i")
h = B("h")

n.s = i
d.v = i
d.w = h
i.s = n
h.v = i
h.w = d
assert i.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.v: A = None
        self.w: B = None
        self.txt = txt

n = A("n")
d = B("d")
i = A("i")
h = B("h")

n.s = i
d.v = i
d.w = h
i.s = n
h.v = i
h.w = d
assert i.s.s.s.s.txt == "i"