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

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

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

class D:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: C = None
        self.o: A = None
        self.t: C = None
        self.txt = txt

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

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

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

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

class D:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: C = None
        self.o: A = None
        self.t: C = None
        self.txt = txt

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

a.o = h
a.r = d
a.q = j
a.p = g
i.v = d
i.w = a
d.u = i
h.x = i
h.p = g
h.o = a
h.t = d
g.u = i
j.o = h
j.r = g
j.q = a
j.p = d
assert g.u.w.q.q.r.txt == "d"