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

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

g = A("g")
l = B("l")
e = B("e")
d = A("d")
c = A("c")
b = B("b")
m = B("m")
i = B("i")
a = B("a")
h = B("h")

g.z = d
g.r = c
l.z = c
l.w = m
e.z = c
e.w = i
d.z = c
d.r = g
c.z = d
c.r = d
b.z = c
b.w = l
m.z = g
m.w = e
i.z = d
i.w = h
a.z = d
a.w = i
h.z = c
h.w = b
assert g.z.z.r.z.r.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: A = None
        self.txt = txt

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

g = A("g")
l = B("l")
e = B("e")
d = A("d")
c = A("c")
b = B("b")
m = B("m")
i = B("i")
a = B("a")
h = B("h")

g.z = d
g.r = c
l.z = c
l.w = m
e.z = c
e.w = i
d.z = c
d.r = g
c.z = d
c.r = d
b.z = c
b.w = l
m.z = g
m.w = e
i.z = d
i.w = h
a.z = d
a.w = i
h.z = c
h.w = b
assert g.z.z.r.z.r.z.z.z.txt == "c"