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

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

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

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

c = A("c")
g = B("g")
e = C("e")
l = D("l")
a = B("a")

c.z = g
c.r = e
g.p = c
g.r = a
g.v = a
e.r = a
e.s = l
l.x = g
a.p = c
a.r = g
a.v = g
assert e.r.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.r: C = None
        self.txt = txt

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

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

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

c = A("c")
g = B("g")
e = C("e")
l = D("l")
a = B("a")

c.z = g
c.r = e
g.p = c
g.r = a
g.v = a
e.r = a
e.s = l
l.x = g
a.p = c
a.r = g
a.v = g
assert e.r.v.p.txt == "c"