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

class B:
    def __init__(self, txt: str):
        self.q: C = None
        self.w: B = None
        self.v: B = None
        self.txt = txt

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

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

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

a.w = b
i.q = h
i.w = n
i.v = n
g.p = h
g.r = n
g.q = n
b.s = g
b.o = g
b.v = a
b.t = a
h.p = g
h.r = n
h.q = i
n.q = g
n.w = i
n.v = i
assert g.r.q.r.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: C = None
        self.w: B = None
        self.v: B = None
        self.txt = txt

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

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

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

a.w = b
i.q = h
i.w = n
i.v = n
g.p = h
g.r = n
g.q = n
b.s = g
b.o = g
b.v = a
b.t = a
h.p = g
h.r = n
h.q = i
n.q = g
n.w = i
n.v = i
assert g.r.q.r.w.q.txt == "h"