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

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

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

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

j = A("j")
n = B("n")
g = C("g")
i = D("i")

j.t = i
j.s = n
n.y = i
n.s = g
g.w = j
i.q = j
assert i.q.s.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.s: B = None
        self.txt = txt

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

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

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

j = A("j")
n = B("n")
g = C("g")
i = D("i")

j.t = i
j.s = n
n.y = i
n.s = g
g.w = j
i.q = j
assert i.q.s.y.q.txt == "j"