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

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

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

d = A("d")
e = B("e")
n = C("n")
g = B("g")
i = A("i")

d.t = i
d.w = i
d.r = e
e.x = n
n.q = d
n.s = d
n.r = e
g.x = n
i.t = d
i.w = d
i.r = g
assert g.x.r.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.w: A = None
        self.r: B = None
        self.txt = txt

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

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

d = A("d")
e = B("e")
n = C("n")
g = B("g")
i = A("i")

d.t = i
d.w = i
d.r = e
e.x = n
n.q = d
n.s = d
n.r = e
g.x = n
i.t = d
i.w = d
i.r = g
assert g.x.r.x.q.txt == "d"