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

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

h = A("h")
a = B("a")
l = B("l")
f = B("f")
g = A("g")
n = A("n")
e = B("e")
b = B("b")

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

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

h = A("h")
a = B("a")
l = B("l")
f = B("f")
g = A("g")
n = A("n")
e = B("e")
b = B("b")

h.w = e
h.o = n
a.z = h
a.r = e
l.z = h
l.r = f
f.z = g
f.r = b
g.w = f
g.o = h
n.w = a
n.o = g
e.z = h
e.r = l
b.z = n
b.r = a
assert g.o.w.z.w.r.r.r.txt == "b"