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

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

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

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

a = A("a")
i = B("i")
k = C("k")
g = D("g")
e = A("e")
n = A("n")
c = C("c")
b = A("b")

a.y = g
i.v = g
k.r = i
k.v = b
k.x = c
g.z = c
g.x = c
g.p = i
e.y = g
n.y = g
c.r = i
c.v = e
c.x = k
b.y = g
assert n.y.x.r.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

a = A("a")
i = B("i")
k = C("k")
g = D("g")
e = A("e")
n = A("n")
c = C("c")
b = A("b")

a.y = g
i.v = g
k.r = i
k.v = b
k.x = c
g.z = c
g.x = c
g.p = i
e.y = g
n.y = g
c.r = i
c.v = e
c.x = k
b.y = g
assert n.y.x.r.v.p.txt == "i"