class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.p: B = 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.x: D = None
        self.r: A = None
        self.p: A = None
        self.txt = txt

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

c = A("c")
g = B("g")
i = C("i")
f = D("f")
a = C("a")

c.u = f
c.p = g
g.v = f
i.x = f
i.r = c
i.p = c
f.p = c
f.r = c
f.z = c
f.s = g
a.x = f
a.r = c
a.p = c
assert f.r.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.p: B = 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.x: D = None
        self.r: A = None
        self.p: A = None
        self.txt = txt

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

c = A("c")
g = B("g")
i = C("i")
f = D("f")
a = C("a")

c.u = f
c.p = g
g.v = f
i.x = f
i.r = c
i.p = c
f.p = c
f.r = c
f.z = c
f.s = g
a.x = f
a.r = c
a.p = c
assert f.r.p.v.txt == "f"