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

class B:
    def __init__(self, txt: str):
        self.s: D = None
        self.w: D = None
        self.r: D = None
        self.txt = txt

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

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

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

d.z = h
d.o = n
n.s = a
n.w = a
n.r = k
h.o = n
h.x = d
f.s = d
f.r = h
f.q = c
c.o = n
c.x = d
k.s = d
k.r = c
k.q = h
a.s = d
a.r = h
a.q = c
assert h.x.o.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.o: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: D = None
        self.w: D = None
        self.r: D = None
        self.txt = txt

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

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

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

d.z = h
d.o = n
n.s = a
n.w = a
n.r = k
h.o = n
h.x = d
f.s = d
f.r = h
f.q = c
c.o = n
c.x = d
k.s = d
k.r = c
k.q = h
a.s = d
a.r = h
a.q = c
assert h.x.o.r.r.x.txt == "d"