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

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

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

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

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

g.t = j
k.r = g
d.y = j
j.z = k
assert j.z.r.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

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

g.t = j
k.r = g
d.y = j
j.z = k
assert j.z.r.t.z.txt == "k"