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

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

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

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

e = A("e")
h = B("h")
a = C("a")
m = D("m")
d = B("d")

e.r = d
e.p = a
e.y = a
h.p = d
a.v = d
a.x = e
a.q = m
m.w = e
d.p = h
assert e.p.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: C = None
        self.y: C = None
        self.txt = txt

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

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

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

e = A("e")
h = B("h")
a = C("a")
m = D("m")
d = B("d")

e.r = d
e.p = a
e.y = a
h.p = d
a.v = d
a.x = e
a.q = m
m.w = e
d.p = h
assert e.p.v.p.txt == "h"