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

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

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

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

f = A("f")
j = B("j")
a = C("a")
k = D("k")
d = B("d")
g = C("g")
m = D("m")

f.v = j
j.r = g
a.p = f
k.s = g
d.r = a
g.p = f
m.s = g
assert a.p.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

f = A("f")
j = B("j")
a = C("a")
k = D("k")
d = B("d")
g = C("g")
m = D("m")

f.v = j
j.r = g
a.p = f
k.s = g
d.r = a
g.p = f
m.s = g
assert a.p.v.r.txt == "g"