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

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

h = A("h")
g = B("g")
n = A("n")
m = A("m")
c = B("c")
k = A("k")
j = B("j")
i = A("i")
b = A("b")

h.o = b
h.r = c
g.z = j
n.o = b
n.r = c
m.o = h
m.r = g
c.z = j
k.o = m
k.r = c
j.z = c
i.o = h
i.r = c
b.o = h
b.r = j
assert n.r.z.z.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.r: B = None
        self.txt = txt

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

h = A("h")
g = B("g")
n = A("n")
m = A("m")
c = B("c")
k = A("k")
j = B("j")
i = A("i")
b = A("b")

h.o = b
h.r = c
g.z = j
n.o = b
n.r = c
m.o = h
m.r = g
c.z = j
k.o = m
k.r = c
j.z = c
i.o = h
i.r = c
b.o = h
b.r = j
assert n.r.z.z.z.z.z.z.z.z.txt == "c"