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

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

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

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

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

b.p = g
b.q = h
h.t = b
h.w = a
h.v = e
e.q = b
g.p = b
g.o = e
g.u = e
g.z = e
a.p = b
a.o = e
a.u = e
a.z = e
assert b.q.t.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.q: B = None
        self.txt = txt

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

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

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

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

b.p = g
b.q = h
h.t = b
h.w = a
h.v = e
e.q = b
g.p = b
g.o = e
g.u = e
g.z = e
a.p = b
a.o = e
a.u = e
a.z = e
assert b.q.t.q.v.txt == "e"