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

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

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

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

d.r = l
i.r = d
i.v = n
i.w = e
e.p = n
e.u = i
l.r = n
n.r = l
j.r = l
j.v = n
j.w = e
assert l.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

d.r = l
i.r = d
i.v = n
i.w = e
e.p = n
e.u = i
l.r = n
n.r = l
j.r = l
j.v = n
j.w = e
assert l.r.r.r.txt == "n"