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

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

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

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

i = A("i")
d = B("d")
k = C("k")
a = D("a")

i.r = k
i.s = k
d.p = k
d.t = a
d.v = i
k.x = d
a.t = i
assert a.t.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.s: C = None
        self.txt = txt

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

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

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

i = A("i")
d = B("d")
k = C("k")
a = D("a")

i.r = k
i.s = k
d.p = k
d.t = a
d.v = i
k.x = d
a.t = i
assert a.t.r.x.txt == "d"