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

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

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

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

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

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

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

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

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

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

k.p = d
d.s = m
f.v = g
f.u = j
m.r = k
m.x = g
g.r = k
g.x = c
j.v = m
j.u = f
c.r = k
c.x = g
assert f.u.v.r.p.txt == "d"