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

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

d = A("d")
l = B("l")
i = B("i")
h = A("h")
c = A("c")
m = A("m")
n = A("n")
f = A("f")
k = A("k")
g = A("g")

d.r = m
d.o = n
l.u = m
l.v = h
i.u = h
i.v = d
h.r = f
h.o = c
c.r = m
c.o = g
m.r = h
m.o = f
n.r = c
n.o = c
f.r = n
f.o = c
k.r = d
k.o = h
g.r = d
g.o = d
assert c.r.o.o.r.o.o.r.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.o: A = None
        self.txt = txt

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

d = A("d")
l = B("l")
i = B("i")
h = A("h")
c = A("c")
m = A("m")
n = A("n")
f = A("f")
k = A("k")
g = A("g")

d.r = m
d.o = n
l.u = m
l.v = h
i.u = h
i.v = d
h.r = f
h.o = c
c.r = m
c.o = g
m.r = h
m.o = f
n.r = c
n.o = c
f.r = n
f.o = c
k.r = d
k.o = h
g.r = d
g.o = d
assert c.r.o.o.r.o.o.r.r.o.r.txt == "m"