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

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

g = A("g")
n = B("n")
a = B("a")
e = A("e")
m = B("m")
h = B("h")

g.w = m
n.w = m
n.z = g
a.w = h
a.z = g
e.w = m
m.w = a
m.z = e
h.w = n
h.z = e
assert g.w.z.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

g = A("g")
n = B("n")
a = B("a")
e = A("e")
m = B("m")
h = B("h")

g.w = m
n.w = m
n.z = g
a.w = h
a.z = g
e.w = m
m.w = a
m.z = e
h.w = n
h.z = e
assert g.w.z.w.w.w.txt == "h"