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

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

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

n.w = a
n.y = i
a.z = i
i.z = a
d.w = a
d.y = a
assert a.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.y: B = None
        self.txt = txt

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

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

n.w = a
n.y = i
a.z = i
i.z = a
d.w = a
d.y = a
assert a.z.z.z.txt == "i"