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

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

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

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

g = A("g")
h = B("h")
n = C("n")
e = D("e")
a = A("a")

g.w = n
h.s = a
h.t = n
h.y = n
h.q = e
n.r = e
n.p = h
e.t = n
a.w = n
assert g.w.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

g = A("g")
h = B("h")
n = C("n")
e = D("e")
a = A("a")

g.w = n
h.s = a
h.t = n
h.y = n
h.q = e
n.r = e
n.p = h
e.t = n
a.w = n
assert g.w.p.q.txt == "e"