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

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

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

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

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

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

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

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

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

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

i.o = j
a.v = i
a.y = g
a.w = j
h.y = a
h.p = i
j.x = a
j.z = g
j.r = g
g.y = a
g.p = i
assert i.o.x.w.r.txt == "g"