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

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

n = A("n")
c = B("c")
h = A("h")
g = A("g")
d = A("d")
f = B("f")
i = B("i")
l = A("l")

n.y = d
c.x = f
c.w = g
h.y = l
g.y = n
d.y = h
f.x = i
f.w = l
i.x = c
i.w = h
l.y = h
assert c.w.y.y.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.x: B = None
        self.w: A = None
        self.txt = txt

n = A("n")
c = B("c")
h = A("h")
g = A("g")
d = A("d")
f = B("f")
i = B("i")
l = A("l")

n.y = d
c.x = f
c.w = g
h.y = l
g.y = n
d.y = h
f.x = i
f.w = l
i.x = c
i.w = h
l.y = h
assert c.w.y.y.y.y.txt == "l"