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

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

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

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

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

h.p = a
h.q = i
g.q = i
g.x = d
g.p = d
g.s = d
i.v = h
i.u = h
i.s = h
i.w = a
a.q = h
a.u = i
e.q = h
e.u = i
d.q = h
d.u = i
assert g.s.u.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.q: C = None
        self.txt = txt

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

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

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

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

h.p = a
h.q = i
g.q = i
g.x = d
g.p = d
g.s = d
i.v = h
i.u = h
i.s = h
i.w = a
a.q = h
a.u = i
e.q = h
e.u = i
d.q = h
d.u = i
assert g.s.u.u.q.txt == "i"