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

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

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

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

h = A("h")
c = B("c")
n = C("n")
l = D("l")
a = D("a")
d = B("d")

h.t = d
h.u = n
h.y = n
h.w = a
c.w = d
c.p = n
c.v = h
c.o = h
n.x = h
n.p = h
n.z = d
l.q = n
a.q = n
d.w = c
d.p = n
d.v = h
d.o = h
assert d.p.p.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.u: C = None
        self.y: C = None
        self.w: D = None
        self.txt = txt

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

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

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

h = A("h")
c = B("c")
n = C("n")
l = D("l")
a = D("a")
d = B("d")

h.t = d
h.u = n
h.y = n
h.w = a
c.w = d
c.p = n
c.v = h
c.o = h
n.x = h
n.p = h
n.z = d
l.q = n
a.q = n
d.w = c
d.p = n
d.v = h
d.o = h
assert d.p.p.t.p.txt == "n"