class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

e = A("e")
d = B("d")
h = C("h")
n = C("n")
i = B("i")
a = A("a")
l = C("l")

e.p = l
d.v = e
d.r = h
d.x = h
h.q = i
n.q = d
i.v = e
i.r = n
i.x = h
a.p = h
l.q = i
assert d.v.p.q.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

e = A("e")
d = B("d")
h = C("h")
n = C("n")
i = B("i")
a = A("a")
l = C("l")

e.p = l
d.v = e
d.r = h
d.x = h
h.q = i
n.q = d
i.v = e
i.r = n
i.x = h
a.p = h
l.q = i
assert d.v.p.q.v.p.txt == "l"