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

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

n = A("n")
i = B("i")
d = B("d")
m = B("m")
g = B("g")
c = A("c")

n.w = m
i.x = d
i.y = g
d.x = g
d.y = i
m.x = i
m.y = d
g.x = m
g.y = m
c.w = i
assert i.y.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

n = A("n")
i = B("i")
d = B("d")
m = B("m")
g = B("g")
c = A("c")

n.w = m
i.x = d
i.y = g
d.x = g
d.y = i
m.x = i
m.y = d
g.x = m
g.y = m
c.w = i
assert i.y.y.x.txt == "i"