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

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

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

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

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

g = A("g")
j = B("j")
d = C("d")
e = D("e")
k = E("k")
a = B("a")

g.r = j
g.y = e
j.v = a
d.p = e
e.r = g
e.p = k
k.r = a
a.v = j
assert d.p.r.y.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: D = None
        self.txt = txt

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

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

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

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

g = A("g")
j = B("j")
d = C("d")
e = D("e")
k = E("k")
a = B("a")

g.r = j
g.y = e
j.v = a
d.p = e
e.r = g
e.p = k
k.r = a
a.v = j
assert d.p.r.y.r.y.txt == "e"