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

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

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

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

i = A("i")
h = B("h")
j = C("j")
n = D("n")
k = C("k")
g = B("g")
d = C("d")
c = C("c")

i.x = c
i.v = j
i.p = k
h.p = n
h.r = i
j.r = d
n.s = k
k.r = d
g.p = n
g.r = i
d.r = c
c.r = d
assert h.r.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.v: C = None
        self.p: C = None
        self.txt = txt

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

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

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

i = A("i")
h = B("h")
j = C("j")
n = D("n")
k = C("k")
g = B("g")
d = C("d")
c = C("c")

i.x = c
i.v = j
i.p = k
h.p = n
h.r = i
j.r = d
n.s = k
k.r = d
g.p = n
g.r = i
d.r = c
c.r = d
assert h.r.v.r.txt == "d"