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

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

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

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

m = A("m")
j = B("j")
h = C("h")
a = D("a")
d = C("d")
c = D("c")
k = A("k")

m.v = c
j.r = d
h.y = j
h.q = a
h.x = d
h.r = m
a.x = k
a.p = j
d.y = j
d.q = c
d.x = h
d.r = m
c.x = m
c.p = j
k.v = c
assert m.v.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

m = A("m")
j = B("j")
h = C("h")
a = D("a")
d = C("d")
c = D("c")
k = A("k")

m.v = c
j.r = d
h.y = j
h.q = a
h.x = d
h.r = m
a.x = k
a.p = j
d.y = j
d.q = c
d.x = h
d.r = m
c.x = m
c.p = j
k.v = c
assert m.v.p.r.txt == "d"