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

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

class C:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

h = A("h")
l = B("l")
e = C("e")
i = D("i")
a = C("a")
n = B("n")
g = D("g")
m = D("m")

h.o = e
h.r = n
l.o = h
e.v = g
i.v = h
a.v = g
n.o = h
g.v = h
m.v = h
assert h.r.o.r.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.r: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

h = A("h")
l = B("l")
e = C("e")
i = D("i")
a = C("a")
n = B("n")
g = D("g")
m = D("m")

h.o = e
h.r = n
l.o = h
e.v = g
i.v = h
a.v = g
n.o = h
g.v = h
m.v = h
assert h.r.o.r.o.o.txt == "e"