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

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

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

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

a = A("a")
i = B("i")
b = C("b")
f = D("f")
k = D("k")

a.y = i
i.u = k
i.p = f
b.v = a
f.x = k
f.y = a
f.v = a
k.x = f
k.y = a
k.v = a
assert k.y.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

a = A("a")
i = B("i")
b = C("b")
f = D("f")
k = D("k")

a.y = i
i.u = k
i.p = f
b.v = a
f.x = k
f.y = a
f.v = a
k.x = f
k.y = a
k.v = a
assert k.y.y.u.txt == "k"