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

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

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

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

f = A("f")
k = B("k")
i = C("i")
g = D("g")

f.p = g
k.r = g
i.v = k
g.v = i
g.u = k
assert g.u.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

f = A("f")
k = B("k")
i = C("i")
g = D("g")

f.p = g
k.r = g
i.v = k
g.v = i
g.u = k
assert g.u.r.v.txt == "i"