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

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

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

i.o = g
i.z = h
d.u = a
d.w = h
n.u = a
n.w = g
h.o = g
h.z = i
g.o = i
g.z = i
a.u = n
a.w = g
assert d.w.z.z.o.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: A = None
        self.txt = txt

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

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

i.o = g
i.z = h
d.u = a
d.w = h
n.u = a
n.w = g
h.o = g
h.z = i
g.o = i
g.z = i
a.u = n
a.w = g
assert d.w.z.z.o.z.o.txt == "g"