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

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

class C:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

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

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

class C:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

h.q = j
h.p = j
j.v = g
j.q = g
j.z = h
i.z = h
g.y = h
g.v = i
g.p = i
g.w = a
a.z = h
assert a.z.p.z.p.v.txt == "g"