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

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

d = A("d")
e = B("e")
i = B("i")
n = A("n")
l = B("l")
j = B("j")
h = A("h")

d.y = n
e.s = n
i.s = h
n.y = d
l.s = n
j.s = n
h.y = n
assert i.s.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

d = A("d")
e = B("e")
i = B("i")
n = A("n")
l = B("l")
j = B("j")
h = A("h")

d.y = n
e.s = n
i.s = h
n.y = d
l.s = n
j.s = n
h.y = n
assert i.s.y.y.txt == "d"