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

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

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

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

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

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

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

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

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

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

h.t = d
h.p = d
h.o = a
h.w = k
g.p = h
k.z = d
k.x = g
k.q = g
d.t = g
a.t = d
a.p = d
a.o = h
a.w = k
assert g.p.t.t.p.w.txt == "k"