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

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

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

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

a = A("a")
h = B("h")
c = C("c")
i = D("i")
k = D("k")
j = D("j")
b = A("b")

a.o = h
a.p = j
a.v = b
h.u = c
h.x = a
c.o = h
i.z = h
k.z = h
j.z = h
b.o = h
b.p = k
b.v = a
assert a.v.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.p: D = None
        self.v: A = None
        self.txt = txt

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

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

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

a = A("a")
h = B("h")
c = C("c")
i = D("i")
k = D("k")
j = D("j")
b = A("b")

a.o = h
a.p = j
a.v = b
h.u = c
h.x = a
c.o = h
i.z = h
k.z = h
j.z = h
b.o = h
b.p = k
b.v = a
assert a.v.p.z.txt == "h"