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

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

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

class D:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: A = None
        self.z: B = None
        self.t: C = None
        self.txt = txt

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

k.w = f
k.r = i
i.r = b
i.t = k
f.t = b
f.v = k
b.p = i
b.z = i
b.q = k
b.t = f
assert b.z.t.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: A = None
        self.z: B = None
        self.t: C = None
        self.txt = txt

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

k.w = f
k.r = i
i.r = b
i.t = k
f.t = b
f.v = k
b.p = i
b.z = i
b.q = k
b.t = f
assert b.z.t.r.t.txt == "k"